The update operation returns a WriteResult object which contains the status of the operation, including whether the db.collection.update() method modified an existing document or added a new document. 

WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : ObjectId("53dbd7c8babeaec6342ed6c8") }) 

The nMatched field shows that the operation matched 0 documents. 

The nUpserted of 1 shows that the update added a document. 

The nModified of 0 specifies that no existing documents were updated. 

The _id field shows the generated _id field for the added document. 

## Additional Examples and Methods 

For more examples, see Update examples in the db.collection.update() reference page. 

The db.collection.findAndModify() and the db.collection.save() method can also modify exist- ing documents or insert a new one. See the individual reference pages for the methods for more information and examples. 

## 3.3.4 Remove Documents 

In MongoDB, the db.collection.remove() method removes documents from a collection. You can remove all documents from a collection, remove all documents that match a condition, or limit the operation to remove just a single document. 

This tutorial provides examples of remove operations using the db.collection.remove() method in the mongo shell. 

## Remove All Documents 

To remove all documents from a collection, pass an empty query document {} to the remove() method. The remove() method does not remove the indexes. 

The following example removes all documents from the inventory collection: 

db.inventory.remove({}) 

To remove all documents from a collection, it may be more efficient to use the drop() method to drop the entire collection, including the indexes, and then recreate the collection and rebuild the indexes. 

## Remove Documents that Match a Condition 

To remove the documents that match a deletion criteria, call the remove() method with the <query> parameter. 

The following example removes all documents from the inventory collection where the type field equals food : 

db.inventory.remove( { type : "food" } ) 

For large deletion operations, it may be more efficient to copy the documents that you want to keep to a new collection and then use drop() on the original collection. 

