O'Reilly logo

Node.js, MongoDB, and AngularJS Web Development by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required