-
Notifications
You must be signed in to change notification settings - Fork 1k
Removing documents
Louis Chatriot edited this page Jun 21, 2013
·
1 revision
db.remove(query, options, callback)
will remove all documents matching query
according to options
-
query
is the same as the ones used for finding and updating -
options
only one option for now:multi
which allows the removal of multiple documents if set to true. Default is false -
callback
is optional, signature: err, numRemoved
// Let's use the same example collection as in the "finding document" part
// { _id: 'id1', planet: 'Mars', system: 'solar', inhabited: false }
// { _id: 'id2', planet: 'Earth', system: 'solar', inhabited: true }
// { _id: 'id3', planet: 'Jupiter', system: 'solar', inhabited: false }
// { _id: 'id4', planet: 'Omicron Persia 8', system: 'futurama', inhabited: true }
// Remove one document from the collection
// options set to {} since the default for multi is false
db.remove({ _id: 'id2' }, {}, function (err, numRemoved) {
// numRemoved = 1
});
// Remove multiple documents
db.remove({ system: 'solar' }, { multi: true }, function (err, numRemoved) {
// numRemoved = 3
// All planets from the solar system were removed
});