db.collection.remove()

You can use db.collection.remove() for deployments hosted in the following environments:

Syntax

The db.collection.remove() method can have one of two syntaxes. The remove() method can take a query document and an optional justOne boolean:

db.collection.remove(
< query >,
)

Or the method can take a query document and an optional remove options document:

Changed in version 5.0.

db.collection.remove(
< query >,
justOne: < boolean >,
writeConcern: document> ,
collation: document> ,
let: document> // Added in MongoDB 5.0
>
)

The remove() method takes the following parameters:

Description

Specifies deletion criteria using query operators. To delete all documents in a collection, pass an empty document ( <> ).

Optional. To limit the deletion to just one document, set to true . Omit to use the default value of false and delete all documents matching the deletion criteria.

writeConcern

Optional. A document expressing the write concern. Omit to use the default write concern. See Write Concern .

Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see Transactions and Write Concern .

Specifies the collation to use for the operation.

Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks.

The collation option has the following syntax:

collation:
locale: ,
caseLevel: ,
caseFirst: ,
strength: ,
numericOrdering: ,
alternate: ,
maxVariable: ,
backwards:
>

When specifying collation, the locale field is mandatory; all other collation fields are optional. For descriptions of the fields, see Collation Document .

If the collation is unspecified but the collection has a default collation (see db.createCollection() ), the operation uses the collation specified for the collection.

If no collation is specified for the collection or for the operations, MongoDB uses the simple binary comparison used in prior versions for string comparisons.

You cannot specify multiple collations for an operation. For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort.

Optional. .. include:: /includes/let-variables-syntax.rst .. include:: /includes/let-variables-syntax-note.rst

For a complete example using let and variables, see Use Variables in let .

New in version 5.0.