MongoDB Tutorial - MongoDB Delete Document

MongoDB's remove() method is used to remove document from the collection.

remove() method accepts two parameters.

  1. deletion criteria: Optional. Deletion criteria according to delete documents.
  2. justOne: Optional. If set to true or 1, then remove only one document.


The syntax of remove() method is as follows



The following code will remove all the documents whose title is 'MongoDB Overview'.

>db.mycol.remove({'title':'MongoDB Overview'})

To delete only first record, set justOne parameter in remove() method.


If you don't specify deletion criteria, MongoDB will delete all documents from the collection. This is equivalent of SQL's truncate command.