May 2015
Beginner
220 pages
4h 16m
English
We should update the API method that returns the pages as objects. Along with the title and description, we have to present a new comments property. Let's open backend/api/pages.js and create a function to fetch comments:
var getComments = function(pageId, callback) {
var collection = db.collection('content');
collection.find({
$query: {
pageId: pageId
},
$orderby: {
date: -1
}
}).toArray(function(err, result) {
result.forEach(function(value, index, arr) {
delete arr[index].userId;
delete arr[index]._id;
});
callback(result);
});
}The key moment in the preceding method is the forming of the MongoDB query. This is the place where we filter the posts and fetch only those that are made for the page that matches the passed ID. ...
Read now
Unlock full access