Add comments to your projects.
Do this by adding a new schema and linking it to the project schema
This lab will get you well-versed in using databases. They will form an important portion of your app and future assignments.
newPost.save(afterSaving);
function afterSaving(err) { // this is a callback
if(err) {console.log(err); res.send(500); }
res.redirect('/');
}
When I run node app.js
I get the following error Error: failed to connect to [localhost:xxxxx]
Mongo isn't running! Did you remember to run the check-setup.sh
script?
When I go to localhost:3000, there are no placeholders like described in the lab slides?
Once you define the schema (next 4 slides), they appear!
I restarted the server, but nothing shows!
In index.js, add a console.log(projects) inside renderProjects. Is your data formatted correctly? Perhaps you need to change the schema. Don't forget to rerun node initDB.js after changing your schema.
I can't access res in my callback.
You need to declare the callback function within the projectInfo function to get access to res.
Remember that the ID field is automatically generated and is called "_id"
Doesn't work and I can't findout why!
In your callback, make sure there's a 'if (err) { console.log(err) }'. What does the console output say?
When I'm working on the delete part , everything is deleted when I click on the delete button. Is there a way to get them back?
You can run node initDB.js. It will reset the db for you.
function deleteCallback(err) {
if(err) { console.log(err); }
...
}
When I add a project using the form, the new project gets added to the top instead of the bottom of the page as it's supposed to. How can I fix this?
The mongoose date constructor seems to choose a random date when only given a month and day. The query displaying the results is sorting by date, if you add a year to your date input it will use that to create the date and place the image in the correct location.
The dates for all the projects are displayed as a day before its actual date.
It is just due to time zone stuff (we are in pacific time not UTC) so the days are off by like 8 hours and that messes with the dates.
Doesn't work sand I can't findout why!
In your callback, make sure there's a 'if (err) { console.log(err) }'. What does the console output say?
function addCallback(err) {
if(err) { console.log(err); }
...
}
git status
git add ...
git commit -m "putting it together lab"
git push
I don't really want to give my credit card to a company I dont trust and am not buying a product from. Is there any alternative to adding this addon?
We don't know of any other way!
heroku create newapplicationname
heroku addons:add mongolab
git push heroku master
heroku run node initDB.js