- MongoDB CRUD Operations >
- Delete Documents
Delete Documents¶
This page provides examples in:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
This page uses the following mongo
shell methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses MongoDB Compass to delete the documents.
Populate the inventory
collection with the following
documents:
This page uses the following PyMongo Python driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following Java Synchronous Driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB Node.js Driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB PHP Library methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following Motor driver methods:
motor.motor_asyncio.AsyncIOMotorCollection.delete_many()
motor.motor_asyncio.AsyncIOMotorCollection.delete_one()
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following Java Reactive Streams Driver methods:
- com.mongodb.reactivestreams.client.MongoCollection.deleteMany
- com.mongodb.reactivestreams.client.MongoCollection.deleteOne
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB C# Driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB Perl Driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB Ruby Driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB Scala Driver methods:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
This page uses the following MongoDB Go Driver functions:
The examples on this page use the inventory
collection. To populate
the inventory
collection, run the following:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
You can run the operation in the web shell below:
For instructions on inserting documents in MongoDB Compass, see Insert Documents.
Note
For complete reference on inserting documents in MongoDB Compass, see the Compass documentation.
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
Delete All Documents
To delete all documents from a collection, pass an empty
filter document {}
to the
db.collection.deleteMany()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter document {}
to the
pymongo.collection.Collection.delete_many()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty org.bson.Document object as the filter to the com.mongodb.client.MongoCollection.deleteMany method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter document {}
to the
Collection.deleteMany()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter document []
to the
MongoDB\Collection::deleteMany()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter document {}
to the
motor.motor_asyncio.AsyncIOMotorCollection.delete_many()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty org.bson.Document object as the filter to the com.mongodb.reactivestreams.client.MongoCollection.deleteMany method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter
Builders<BsonDocument>.Filter.Empty
to the
IMongoCollection.DeleteMany() method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter document {}
to the
MongoDB::Collection::delete_many()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter document {}
to the
Mongo::Collection#delete_many()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty
filter Document()
to the
collection.deleteMany()
method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an empty filter document to the Collection.DeleteMany function.
The following example deletes all documents from the inventory
collection:
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
The method returns a document with the status of the operation. For
more information and examples, see
deleteMany()
.
The delete_many()
method returns an instance of
pymongo.results.DeleteResult
with the status of the
operation.
The com.mongodb.client.MongoCollection.deleteMany method returns an instance of com.mongodb.client.result.DeleteResult with the status of the operation.
deleteMany() returns a
promise that provides a result
. The result.deletedCount
property contains the number of documents that matched the
filter.
Upon successful execution, the
deleteMany()
method returns an instance of
MongoDB\DeleteResult
whose getDeletedCount()
method returns the number of documents that matched the filter.
The delete_many()
coroutine asynchronously returns an instance of
pymongo.results.DeleteResult
with the status of the
operation.
com.mongodb.reactivestreams.client.MongoCollection.deleteMany
returns a Publisher
object of type com.mongodb.client.result.DeleteResult if
successful. Returns an instance of com.mongodb.MongoException
if unsuccessful.
Upon successful execution, the
IMongoCollection.DeleteMany()
method returns an instance of
DeleteResult whose
DeletedCount
property contains the number of documents
that matched the filter.
Upon successful execution, the
delete_many() method
returns an instance of
MongoDB::DeleteResult whose
deleted_count
attribute contains the number of documents
that matched the filter.
Upon successful execution, the
delete_many() method
returns an instance of
Mongo::Operation::Result, whose
deleted_count
attribute contains the number of documents
that matched the filter.
Upon successful execution, the
collection.deleteMany() method
returns an
Observable
with a single element with a DeleteResult
type parameter or with
an com.mongodb.MongoException
.
Upon successful execution, the
Collection.DeleteMany
function returns an instance of
DeleteResult whose
DeletedCount
property contains the number of documents
that matched the filter.
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a
filter parameter to the
deleteMany()
method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a
filter parameter to the
delete_many()
method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the com.mongodb.client.MongoCollection.deleteMany method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a
filter parameter to the
deleteMany()
method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a
filter parameter to the
delete_many()
method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the com.mongodb.reactivestreams.client.MongoCollection.deleteMany method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the IMongoCollection.DeleteMany() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the delete_many() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the delete_many() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field>:<value>
expressions in the
query filter document:
To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:
To specify equality conditions, construct a filter using the Eq method:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use <field> => <value>
expressions in the
query filter document:
To specify equality conditions, use the
com.mongodb.client.model.Filters.eq_
method to create the
query filter document:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:
A query filter document can use the query operators to specify conditions in the following form:
A query filter document can use the query operators to specify conditions in the following form:
In addition to the equality condition, MongoDB provides
various query operators to specify
filter conditions. Use the
com.mongodb.client.model.Filters_
helper methods to
facilitate the creation of filter documents. For example:
To delete all documents that match a deletion criteria, pass a filter parameter to the Collection.DeleteMany function.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
The method returns a document with the status of the operation. For
more information and examples, see
deleteMany()
.
The delete_many()
method returns an instance of
pymongo.results.DeleteResult
with the status of the
operation.
The com.mongodb.client.MongoCollection.deleteMany method returns an instance of com.mongodb.client.result.DeleteResult with the status of the operation.
deleteMany() returns a
promise that provides a result
. The result.deletedCount
property contains the number of documents that matched the
filter.
Upon successful execution, the
deleteMany()
method returns an instance of
MongoDB\DeleteResult
whose getDeletedCount()
method returns the number of documents that matched the filter.
The delete_many()
coroutine asynchronously returns an instance of
pymongo.results.DeleteResult
with the status of the
operation.
com.mongodb.reactivestreams.client.MongoCollection.deleteMany
returns a Publisher
object of type com.mongodb.client.result.DeleteResult if
successful. Returns an instance of com.mongodb.MongoException
if unsuccessful.
Upon successful execution, the
IMongoCollection.DeleteMany()
method returns an instance of
DeleteResult whose
DeletedCount
property contains the number of documents
that matched the filter.
Upon successful execution, the
delete_many() method
returns an instance of
MongoDB::DeleteResult whose
deleted_count
attribute contains the number of documents
that matched the filter.
Upon successful execution, the
delete_many() method
returns an instance of
Mongo::Operation::Result, whose
deleted_count
attribute contains the number of documents
that matched the filter.
Upon successful execution, the
collection.deleteMany() method
returns an
Observable
with a single element with a DeleteResult
type parameter or with
an com.mongodb.MongoException
.
Upon successful execution, the
Collection.DeleteMany
function returns an instance of
DeleteResult whose
DeletedCount
property contains the number of documents
that matched the filter.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified
filter (even though multiple documents may match the specified
filter) use the db.collection.deleteOne()
method.
The following example deletes the first document where status
is
"D"
:
Delete a Single Document
MongoDB Compass provides a simple way to delete a document
from a collection. The following example shows how to delete
the document with item
equal to paper
from the
inventory
collection:
Note
In this example we are using the Compass Table View to delete the document. The deletion process using the Compass List View follows a very similar approach.
For more information on the differences between Table View and List View in Compass, refer to the Compass documentation.
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified
filter (even though multiple documents may match the specified
filter) use the
pymongo.collection.Collection.delete_one()
method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the com.mongodb.client.MongoCollection.deleteOne method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the Collection.deleteOne() method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified
filter (even though multiple documents may match the specified
filter) use the
MongoDB\Collection::deleteOne()
method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified
filter (even though multiple documents may match the specified
filter) use the
motor.motor_asyncio.AsyncIOMotorCollection.delete_one()
method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the com.mongodb.reactivestreams.client.MongoCollection.deleteMany method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the IMongoCollection.DeleteOne() method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the MongoDB::Collection::delete_one() method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the Mongo::Collection#delete_one() method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the collection.deleteOne() method.
The following example deletes the first document where status
is
"D"
:
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the Collection.DeleteOne function.
The following example deletes the first document where status
is
"D"
:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
Click the Table button in the top navigation to access the Table View:
Use the Compass query bar to locate the target document.
Copy the following filter document into the query bar and click Find:
Hover over the document and click the trash icon which appears on the right-hand side:
After clicking the delete button, the document is flagged for deletion and Compass asks for confirmation that you want to remove the document:
Click Delete to confirm. Compass deletes the document from the collection.
Delete Behavior¶
Indexes¶
Delete operations do not drop indexes, even if deleting all documents from a collection.
Atomicity¶
All write operations in MongoDB are atomic on the level of a single document. For more information on MongoDB and atomicity, see Atomicity and Transactions.
Write Acknowledgement¶
With write concerns, you can specify the level of acknowledgement requested from MongoDB for write operations. For details, see Write Concern.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
See also
See also
motor.motor_asyncio.AsyncIOMotorCollection.delete_many()
motor.motor_asyncio.AsyncIOMotorCollection.delete_one()
- Additional Methods