June 2014
Intermediate to advanced
696 pages
38h 52m
English
Listing 27.7 implements the route handling code for the Photo model. There are two routes handled. The getPhoto() route handler looks up a single Photo document, based on the _id field passed in as photoId in the GET query string. The getPhotos() route handler retrieves all Photo documents. Both handlers return a JSON string form of the results.
Listing 27.7 photos_controller.js: Implementing the getPhoto and getPhoto routes in the Express server to get photos
01 var mongoose = require('mongoose'),02 Photo = mongoose.model('Photo');03 exports.getPhoto = function(req, res) {04 Photo.findOne({ _id: req.query.photoId })05 .exec(function(err, photo) {06 if (!photo){ ...
Read now
Unlock full access