June 2014
Intermediate to advanced
696 pages
38h 52m
English
The Document object provides the remove() method, which allows you to delete a single document from the model. The syntax for the remove() method on Document objects is shown below:
remove( [callback])
The callback parameter accepts an error as the only argument if an error occurred or the deleted document as the second if the delete was successful.
Listing 16.8 shows an example of using the remove() method to remove the word unhappy. Figure 16.8 shows the output for Listing 16.8.
Listing 16.8 mongoose_remove_one.js: Deleting a document from a collection by using Mongoose
01 var mongoose = require('mongoose');02 var db = mongoose.connect('mongodb://localhost/words');03 var wordSchema = ...
Read now
Unlock full access