MongoDB

Remove

Posted on 02nd September 2014

The remove() method of a MongoDB collection is used to delete documents from that collection. The remove() method takes a "delete criteria" document and an optional "remove options" document as parameters

Syntax

{ delete_criteria }

The delete_criteria parameter is a document that specifies the condition used to select the documents for deletion. An empty query document ({}) will delete all documents in the collection.

Optionally you can pass a "remove options" document to the remove() method. The remove options document can have two parameters:

justOne

This is an optional parameter and can be set to either true or false. If set to true, only one document that match the delete criteria is deleted. The default value is false which will delete all documents that match the delete criteria.

writeConcern

The writeConcern parameter is optional and it is used to specify the write concern which is the level of guarantee that MongoDB provides for a write operation.

Example

The following example removes documents whose title field has the value The book thief in the movie collection.