- Delete Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete All Documents that Match a Condition
- Delete Only One Document that Matches a Condition
- Delete a Single Document
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Only One Document that Matches a Condition
- Delete Behavior
Delete Documents
This page provides examples in:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
This page uses the following mongo
shell methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses MongoDB Compass todelete the documents.
Populate the inventory
collection with the followingdocuments:
This page uses thefollowing PyMongoPython driver methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing Java Synchronous Driver methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB Node.js Driver methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB PHP Library methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing Motordriver methods:
motor.motor_asyncio.AsyncIOMotorCollection.delete_many()
motor.motor_asyncio.AsyncIOMotorCollection.delete_one()
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing 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 populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB C# Driver methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB Perl Driver methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB Ruby Driver methods:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB Scala Driver methods:
- collection.deleteMany():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])
- collection.deleteOne():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
This page uses thefollowing MongoDB Go Driver functions:
The examples on this page use the inventory
collection. To populatethe inventory
collection, run the following:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
- db.inventory.insertMany( [
- { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
- { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
- { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
- { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
- { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
- ] );
You can run the operation in the web shell below:
- [
- { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
- { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
- { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
- { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
- { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
- ]
For instructions on inserting documents in MongoDB Compass, seeInsert Documents.
Note
For complete reference on inserting documents in MongoDBCompass, see theCompass documentation.
- db.inventory.insert_many([
- {"item": "journal",
- "qty": 25,
- "size": {"h": 14, "w": 21, "uom": "cm"},
- "status": "A"},
- {"item": "notebook",
- "qty": 50,
- "size": {"h": 8.5, "w": 11, "uom": "in"},
- "status": "P"},
- {"item": "paper",
- "qty": 100,
- "size": {"h": 8.5, "w": 11, "uom": "in"},
- "status": "D"},
- {"item": "planner",
- "qty": 75,
- "size": {"h": 22.85, "w": 30, "uom": "cm"},
- "status": "D"},
- {"item": "postcard",
- "qty": 45,
- "size": {"h": 10, "w": 15.25, "uom": "cm"},
- "status": "A"}])
- collection.insertMany(asList(
- Document.parse("{ item: 'journal', qty: 25, size: { h: 14, w: 21, uom: 'cm' }, status: 'A' }"),
- Document.parse("{ item: 'notebook', qty: 50, size: { h: 8.5, w: 11, uom: 'in' }, status: 'A' }"),
- Document.parse("{ item: 'paper', qty: 100, size: { h: 8.5, w: 11, uom: 'in' }, status: 'D' }"),
- Document.parse("{ item: 'planner', qty: 75, size: { h: 22.85, w: 30, uom: 'cm' }, status: 'D' }"),
- Document.parse("{ item: 'postcard', qty: 45, size: { h: 10, w: 15.25, uom: 'cm' }, status: 'A' }")
- ));
- await db.collection('inventory').insertMany([
- {
- item: 'journal',
- qty: 25,
- size: { h: 14, w: 21, uom: 'cm' },
- status: 'A'
- },
- {
- item: 'notebook',
- qty: 50,
- size: { h: 8.5, w: 11, uom: 'in' },
- status: 'P'
- },
- {
- item: 'paper',
- qty: 100,
- size: { h: 8.5, w: 11, uom: 'in' },
- status: 'D'
- },
- {
- item: 'planner',
- qty: 75,
- size: { h: 22.85, w: 30, uom: 'cm' },
- status: 'D'
- },
- {
- item: 'postcard',
- qty: 45,
- size: { h: 10, w: 15.25, uom: 'cm' },
- status: 'A'
- }
- ]);
- $insertManyResult = $db->inventory->insertMany([
- [
- 'item' => 'journal',
- 'qty' => 25,
- 'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
- 'status' => 'A',
- ],
- [
- 'item' => 'notebook',
- 'qty' => 50,
- 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
- 'status' => 'P',
- ],
- [
- 'item' => 'paper',
- 'qty' => 100,
- 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
- 'status' => 'D',
- ],
- [
- 'item' => 'planner',
- 'qty' => 75,
- 'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'],
- 'status' => 'D',
- ],
- [
- 'item' => 'postcard',
- 'qty' => 45,
- 'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'],
- 'status' => 'A',
- ],
- ]);
- await db.inventory.insert_many([
- {"item": "journal",
- "qty": 25,
- "size": {"h": 14, "w": 21, "uom": "cm"},
- "status": "A"},
- {"item": "notebook",
- "qty": 50,
- "size": {"h": 8.5, "w": 11, "uom": "in"},
- "status": "P"},
- {"item": "paper",
- "qty": 100,
- "size": {"h": 8.5, "w": 11, "uom": "in"},
- "status": "D"},
- {"item": "planner",
- "qty": 75,
- "size": {"h": 22.85, "w": 30, "uom": "cm"},
- "status": "D"},
- {"item": "postcard",
- "qty": 45,
- "size": {"h": 10, "w": 15.25, "uom": "cm"},
- "status": "A"}])
- Publisher<Success> insertManyPublisher = collection.insertMany(asList(
- Document.parse("{ item: 'journal', qty: 25, size: { h: 14, w: 21, uom: 'cm' }, status: 'A' }"),
- Document.parse("{ item: 'notebook', qty: 50, size: { h: 8.5, w: 11, uom: 'in' }, status: 'A' }"),
- Document.parse("{ item: 'paper', qty: 100, size: { h: 8.5, w: 11, uom: 'in' }, status: 'D' }"),
- Document.parse("{ item: 'planner', qty: 75, size: { h: 22.85, w: 30, uom: 'cm' }, status: 'D' }"),
- Document.parse("{ item: 'postcard', qty: 45, size: { h: 10, w: 15.25, uom: 'cm' }, status: 'A' }")
- ));
- var documents = new[]
- {
- new BsonDocument
- {
- { "item", "journal" },
- { "qty", 25 },
- { "size", new BsonDocument { { "h", 14 }, { "w", 21 }, { "uom", "cm" } } },
- { "status", "A" }
- },
- new BsonDocument
- {
- { "item", "notebook" },
- { "qty", 50 },
- { "size", new BsonDocument { { "h", 8.5 }, { "w", 11 }, { "uom", "in" } } },
- { "status", "P" }
- },
- new BsonDocument
- {
- { "item", "paper" },
- { "qty", 100 },
- { "size", new BsonDocument { { "h", 8.5 }, { "w", 11 }, { "uom", "in" } } },
- { "status", "D" }
- },
- new BsonDocument
- {
- { "item", "planner" },
- { "qty", 75 },
- { "size", new BsonDocument { { "h", 22.85 }, { "w", 30 }, { "uom", "cm" } } },
- { "status", "D" }
- },
- new BsonDocument
- {
- { "item", "postcard" },
- { "qty", 45 },
- { "size", new BsonDocument { { "h", 10 }, { "w", 15.25 }, { "uom", "cm" } } },
- { "status", "A" }
- }
- };
- collection.InsertMany(documents);
- $db->coll("inventory")->insert_many(
- [
- {
- item => "journal",
- qty => 25,
- size => { h => 14, w => 21, uom => "cm" },
- status => "A"
- },
- {
- item => "notebook",
- qty => 50,
- size => { h => 8.5, w => 11, uom => "in" },
- status => "P"
- },
- {
- item => "paper",
- qty => 100,
- size => { h => 8.5, w => 11, uom => "in" },
- status => "D"
- },
- {
- item => "planner",
- qty => 75,
- size => { h => 22.85, w => 30, uom => "cm" },
- status => "D"
- },
- {
- item => "postcard",
- qty => 45,
- size => { h => 10, w => 15.25, uom => "cm" },
- status => "A"
- }
- ]
- );
- client[:inventory].insert_many([
- { item: 'journal',
- qty: 25,
- size: { h: 14, w: 21, uom: 'cm' },
- status: 'A' },
- { item: 'notebook',
- qty: 50,
- size: { h: 8.5, w: 11, uom: 'in' },
- status: 'P' },
- { item: 'paper',
- qty: 100,
- size: { h: 8.5, w: 11, uom: 'in' },
- status: 'D' },
- { item: 'planner',
- qty: 75,
- size: { h: 22.85, w: 30, uom: 'cm' },
- status: 'D' },
- { item: 'postcard',
- qty: 45,
- size: { h: 10, w: 15.25, uom: 'cm' },
- status: 'A' },
- ])
- collection.insertMany(Seq(
- Document("""{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" }"""),
- Document("""{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "A" }"""),
- Document("""{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" }"""),
- Document("""{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" }"""),
- Document("""{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }""")
- )).execute()
- docs := []interface{}{
- bson.D{
- {"item", "journal"},
- {"qty", 25},
- {"size", bson.D{
- {"h", 14},
- {"w", 21},
- {"uom", "cm"},
- }},
- {"status", "A"},
- },
- bson.D{
- {"item", "notebook"},
- {"qty", 50},
- {"size", bson.D{
- {"h", 8.5},
- {"w", 11},
- {"uom", "in"},
- }},
- {"status", "P"},
- },
- bson.D{
- {"item", "paper"},
- {"qty", 100},
- {"size", bson.D{
- {"h", 8.5},
- {"w", 11},
- {"uom", "in"},
- }},
- {"status", "D"},
- },
- bson.D{
- {"item", "planner"},
- {"qty", 75},
- {"size", bson.D{
- {"h", 22.85},
- {"w", 30},
- {"uom", "cm"},
- }},
- {"status", "D"},
- },
- bson.D{
- {"item", "postcard"},
- {"qty", 45},
- {"size", bson.D{
- {"h", 10},
- {"w", 15.25},
- {"uom", "cm"},
- }},
- {"status", "A"},
- },
- }
- result, err := coll.InsertMany(context.Background(), docs)
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
Delete All Documents
To delete all documents from a collection, pass an emptyfilter document {}
to thedb.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 emptyfilter document {}
to thepymongo.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 emptyorg.bson.Document object as thefilter to thecom.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 emptyfilter document {}
to theCollection.deleteMany()method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an emptyfilter document []
to theMongoDB\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 emptyfilter document {}
to themotor.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 emptyorg.bson.Document object as thefilter to thecom.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 emptyfilterBuilders<BsonDocument>.Filter.Empty
to theIMongoCollection.DeleteMany() method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an emptyfilter document {}
to theMongoDB::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 emptyfilter document {}
to theMongo::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 emptyfilter Document()
to thecollection.deleteMany():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])method.
The following example deletes all documents from the inventory
collection:
Delete All Documents
To delete all documents from a collection, pass an emptyfilter document to theCollection.DeleteMany function.
The following example deletes all documents from the inventory
collection:
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
- db.inventory.deleteMany({})
- db.inventory.delete_many({})
- collection.deleteMany(new Document());
- await db.collection('inventory').deleteMany({});
- $deleteResult = $db->inventory->deleteMany([]);
- await db.inventory.delete_many({})
- Publisher<DeleteResult> deleteManyPublisher = collection.deleteMany(new Document());
- var filter = Builders<BsonDocument>.Filter.Empty;
- var result = collection.DeleteMany(filter);
- $db->coll("inventory")->delete_many( {} );
- client[:inventory].delete_many({})
- collection.deleteMany(Document()).execute()
- result, err := coll.DeleteMany(context.Background(), bson.D{})
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
The method returns a document with the status of the operation. Formore information and examples, seedeleteMany()
.
The delete_many()
method returns an instance ofpymongo.results.DeleteResult
with the status of theoperation.
The com.mongodb.client.MongoCollection.deleteManymethod returns an instance ofcom.mongodb.client.result.DeleteResultwith the status of theoperation.
deleteMany() returns apromise that provides a result
. The result.deletedCount
property contains the number of documents that matched thefilter.
Upon successful execution, thedeleteMany()
method returns an instance ofMongoDB\DeleteResult
whose getDeletedCount()
method returns the number of documents that matched the filter.
The delete_many()
coroutine asynchronously returns an instance ofpymongo.results.DeleteResult
with the status of theoperation.
com.mongodb.reactivestreams.client.MongoCollection.deleteMany)returns a Publisherobject of type com.mongodb.client.result.DeleteResult ifsuccessful. Returns an instance of com.mongodb.MongoException
if unsuccessful.
Upon successful execution, theIMongoCollection.DeleteMany()method returns an instance ofDeleteResult whoseDeletedCount
property contains the number of documentsthat matched the filter.
Upon successful execution, thedelete_many() methodreturns an instance ofMongoDB::DeleteResult whosedeleted_count
attribute contains the number of documentsthat matched the filter.
Upon successful execution, thedelete_many() methodreturns an instance ofMongo::Operation::Result, whosedeleted_count
attribute contains the number of documentsthat matched the filter.
Upon successful execution, thecollection.deleteMany():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult]) methodreturns anObservablewith a single element with a DeleteResult
type parameter or withan com.mongodb.MongoException
.
Upon successful execution, theCollection.DeleteManyfunction returns an instance ofDeleteResult whoseDeletedCount
property contains the number of documentsthat matched the filter.
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedeleteMany()
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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedelete_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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thecom.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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedeleteMany()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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedeleteMany()
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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedelete_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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thecom.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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to theIMongoCollection.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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedelete_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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedelete_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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to thedeleteMany():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])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 todelete. The filters use the same syntaxas read operations.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- [ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
- { <field1>: <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:
- and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)
To specify equality conditions, construct a filter using theEq method:
- Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
- { <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
- and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- [ <field1> => [ <operator1> => <value1> ], ... ]
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1>: { <operator1>: <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))
In addition to the equality filter, MongoDB providesvarious query operators to specifyfilter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
- var builder = Builders<BsonDocument>.Filter;
- builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
A query filter document canuse the query operators to specifyconditions in the following form:
- { <field1> => { <operator1> => <value1> }, ... }
In addition to the equality condition, MongoDB providesvarious query operators to specifyfilter conditions. Use thecom.mongodb.client.model.Filters_
helper methods tofacilitate the creation of filter documents. For example:
- and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))
To delete all documents that match a deletion criteria, pass afilter parameter to theCollection.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
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
- db.inventory.deleteMany({ status : "A" })
- db.inventory.delete_many({"status": "A"})
- collection.deleteMany(eq("status", "A"));
- await db.collection('inventory').deleteMany({ status: 'A' });
- $deleteResult = $db->inventory->deleteMany(['status' => 'A']);
- await db.inventory.delete_many({"status": "A"})
- deleteManyPublisher = collection.deleteMany(eq("status", "A"));
- var filter = Builders<BsonDocument>.Filter.Eq("status", "A");
- var result = collection.DeleteMany(filter);
- $db->coll("inventory")->delete_many( { status => "A" } );
- client[:inventory].delete_many(status: 'A')
- collection.deleteMany(equal("status", "A")).execute()
- result, err := coll.DeleteMany(
- context.Background(),
- bson.D{
- {"status", "A"},
- },
- )
- Mongo Shell
- Python
- Java (Sync)
- Node.js
- PHP
- Other
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
The method returns a document with the status of the operation. Formore information and examples, seedeleteMany()
.
The delete_many()
method returns an instance ofpymongo.results.DeleteResult
with the status of theoperation.
The com.mongodb.client.MongoCollection.deleteManymethod returns an instance ofcom.mongodb.client.result.DeleteResultwith the status of theoperation.
deleteMany() returns apromise that provides a result
. The result.deletedCount
property contains the number of documents that matched thefilter.
Upon successful execution, thedeleteMany()
method returns an instance ofMongoDB\DeleteResult
whose getDeletedCount()
method returns the number of documents that matched the filter.
The delete_many()
coroutine asynchronously returns an instance ofpymongo.results.DeleteResult
with the status of theoperation.
com.mongodb.reactivestreams.client.MongoCollection.deleteMany)returns a Publisherobject of type com.mongodb.client.result.DeleteResult ifsuccessful. Returns an instance of com.mongodb.MongoException
if unsuccessful.
Upon successful execution, theIMongoCollection.DeleteMany()method returns an instance ofDeleteResult whoseDeletedCount
property contains the number of documentsthat matched the filter.
Upon successful execution, thedelete_many() methodreturns an instance ofMongoDB::DeleteResult whosedeleted_count
attribute contains the number of documentsthat matched the filter.
Upon successful execution, thedelete_many() methodreturns an instance ofMongo::Operation::Result, whosedeleted_count
attribute contains the number of documentsthat matched the filter.
Upon successful execution, thecollection.deleteMany():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult]) methodreturns anObservablewith a single element with a DeleteResult
type parameter or withan com.mongodb.MongoException
.
Upon successful execution, theCollection.DeleteManyfunction returns an instance ofDeleteResult whoseDeletedCount
property contains the number of documentsthat matched the filter.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specifiedfilter (even though multiple documents may match the specifiedfilter) 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 documentfrom a collection. The following example shows how to deletethe document with item
equal to paper
from theinventory
collection:
Note
In this example we are using the CompassTable View to delete thedocument. The deletion process using the CompassList View follows a verysimilar approach.
For more information on the differences between Table Viewand List View in Compass, refer to theCompass documentation.
Delete Only One Document that Matches a Condition
To delete at most a single document that matches a specifiedfilter (even though multiple documents may match the specifiedfilter) use thepymongo.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 specifiedfilter (even though multiple documents may match the specifiedfilter) use the com.mongodb.client.MongoCollection.deleteOnemethod.
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 specifiedfilter (even though multiple documents may match the specifiedfilter) use theCollection.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 specifiedfilter (even though multiple documents may match the specifiedfilter) use theMongoDB\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 specifiedfilter (even though multiple documents may match the specifiedfilter) use themotor.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 specifiedfilter (even though multiple documents may match the specifiedfilter) 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 specifiedfilter (even though multiple documents may match the specifiedfilter) use theIMongoCollection.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 specifiedfilter (even though multiple documents may match the specifiedfilter) use theMongoDB::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 specifiedfilter (even though multiple documents may match the specifiedfilter) use theMongo::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 specifiedfilter (even though multiple documents may match the specifiedfilter) use thecollection.deleteOne():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])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 specifiedfilter (even though multiple documents may match the specifiedfilter) use theCollection.DeleteOne function.
The following example deletes the first document where status
is"D"
:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
- db.inventory.deleteOne( { status: "D" } )
- Click the Table button in the top navigationto access the Table View:
- Use the Compass query bar tolocate the target document.
Copy the following filter document into the query bar and clickFind:
- { item: "paper" }
- Hover over the document and click the trash icon whichappears on the right-hand side:
After clicking the delete button, the document is flaggedfor deletion and Compass asks for confirmation that youwant to remove the document:
- Click Delete to confirm. Compass deletes thedocument from the collection.
- db.inventory.delete_one({"status": "D"})
- collection.deleteOne(eq("status", "D"));
- await db.collection('inventory').deleteOne({ status: 'D' });
- $deleteResult = $db->inventory->deleteOne(['status' => 'D']);
- await db.inventory.delete_one({"status": "D"})
- Publisher<DeleteResult> deleteOnePublisher = collection.deleteOne(eq("status", "D"));
- var filter = Builders<BsonDocument>.Filter.Eq("status", "D");
- var result = collection.DeleteOne(filter);
- $db->coll("inventory")->delete_one( { status => "D" } );
- client[:inventory].delete_one(status: 'D')
- collection.deleteOne(equal("status", "D")).execute()
- result, err := coll.DeleteOne(
- context.Background(),
- bson.D{
- {"status", "D"},
- },
- )
Delete Behavior
Indexes
Delete operations do not drop indexes, even if deleting all documentsfrom a collection.
Atomicity
All write operations in MongoDB are atomic on the level of a singledocument. For more information on MongoDB and atomicity, seeAtomicity and Transactions.
Write Acknowledgement
With write concerns, you can specify the level of acknowledgementrequested from MongoDB for write operations. For details, seeWrite Concern.
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
- Go
See also
See also
See also
pymongo.collection.Collection.delete_many()
pymongo.collection.Collection.delete_one()
- Additional Methods
See also
- com.mongodb.client.MongoCollection.deleteMany
- com.mongodb.client.MongoCollection.deleteOne
- Additional Java Synchronous Driver Write Examples
See also
See also
See also
motor.motor_asyncio.AsyncIOMotorCollection.delete_many()
motor.motor_asyncio.AsyncIOMotorCollection.delete_one()
- Additional Methods
See also
- com.mongodb.reactivestreams.client.MongoCollection.deleteMany)
- com.mongodb.reactivestreams.client.MongoCollection.deleteOne)
- Java Reactive Streams Driver Quick Tour
See also
See also
See also
See also
- collection.deleteMany():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])
- collection.deleteOne():org.mongodb.scala.SingleObservable[org.mongodb.scala.result.DeleteResult])
- Additional Methods
See also