remove() - Remove data from a collection command

Removes all the data or specified data from a collection. Index definitions are retained.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. remove(query)

Command parameters

query
This optional string parameter specifies a JSON query to filter a subset of data.

Example

Example 1: Remove all documents from the books collection.
db.books.remove()
Sample output is as follows:
Removed 15 row(s).
Example 2: Remove a book from the collection by specifying an ISBN:
db.books.remove({isbn: "123-456-789"})
Sample output is as follows:
Removed 1 row(s).