June 2014
Intermediate to advanced
696 pages
38h 52m
English
First, you need to implement the route handler that will interact with the Word model to retrieve the words from MongoDB. Listing 29.16 implements the getWords() route handler for the /words route. This handler reads the limit, skip, sort, and direction parameters from the query and uses them to query the MongoDB database.
The getSortObj() function transforms the sort fields and direction into the sort object that will be used in the .sort() method on the Query object.
Listing 29.16 words_controller.js: Implementing the backend word route controller to support the /words route
01 var mongoose = require('mongoose'),02 Word = mongoose.model('Word');03 ...
Read now
Unlock full access