Querying a collection
The server did restart when we saved our changes. At this point, Meteor added five post examples to our database.
Note
If the server didn't restart, it means that we made a mistake in the syntax somewhere in our code. When we manually reload our browser or check out the terminal, we will see the error that Meteor gives us and we can fix it.
In case we messed up something in the database, we can always reset it using the $ meteor reset
command in the terminal.
We can see these posts by simply opening up the console in our browser and typing the following command:
Posts.find().fetch();
This will return an array with five items, each of them being one of our example posts.
To list these newly inserted posts in our front page, we need to replace the content of our postsList
helper in the home.js
file with the following lines of code:
Template.home.helpers({ postsList: function(){ return Posts.find({}, {sort: {timeCreated: -1}}); } });
As we can see, we returned the...