Implementing the CommentThread Model Controller

Listing 27.8 implements the route handling code for the CommentThread model. Two routes are handled: getComment() and addComment(). Due to the size of the file, the code for these two routes is broken down in the following sections.

Implementing the getComment() Route

The getComment() route handler looks up a single CommentThread document, based on the _id field passed in as commentId in the GET request query string.

Listing 27.8 comments_controller.js-getComment: Implementing the route to get comment threads for the Express server

04 exports.getComment = function(req, res) {05   CommentThread.findOne({ _id: req.query.commentId })06   .exec(function(err, comment) ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.