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:

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:

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:

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
  1. db.inventory.insertMany( [
  2. { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
  3. { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
  4. { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
  5. { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
  6. { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
  7. ] );

You can run the operation in the web shell below:

  1. [
  2. { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
  3. { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
  4. { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
  5. { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
  6. { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
  7. ]

For instructions on inserting documents in MongoDB Compass, seeInsert Documents.

Note

For complete reference on inserting documents in MongoDBCompass, see theCompass documentation.

  1. db.inventory.insert_many([
  2. {"item": "journal",
  3. "qty": 25,
  4. "size": {"h": 14, "w": 21, "uom": "cm"},
  5. "status": "A"},
  6. {"item": "notebook",
  7. "qty": 50,
  8. "size": {"h": 8.5, "w": 11, "uom": "in"},
  9. "status": "P"},
  10. {"item": "paper",
  11. "qty": 100,
  12. "size": {"h": 8.5, "w": 11, "uom": "in"},
  13. "status": "D"},
  14. {"item": "planner",
  15. "qty": 75,
  16. "size": {"h": 22.85, "w": 30, "uom": "cm"},
  17. "status": "D"},
  18. {"item": "postcard",
  19. "qty": 45,
  20. "size": {"h": 10, "w": 15.25, "uom": "cm"},
  21. "status": "A"}])
  1. collection.insertMany(asList(
  2. Document.parse("{ item: 'journal', qty: 25, size: { h: 14, w: 21, uom: 'cm' }, status: 'A' }"),
  3. Document.parse("{ item: 'notebook', qty: 50, size: { h: 8.5, w: 11, uom: 'in' }, status: 'A' }"),
  4. Document.parse("{ item: 'paper', qty: 100, size: { h: 8.5, w: 11, uom: 'in' }, status: 'D' }"),
  5. Document.parse("{ item: 'planner', qty: 75, size: { h: 22.85, w: 30, uom: 'cm' }, status: 'D' }"),
  6. Document.parse("{ item: 'postcard', qty: 45, size: { h: 10, w: 15.25, uom: 'cm' }, status: 'A' }")
  7. ));
  1. await db.collection('inventory').insertMany([
  2. {
  3. item: 'journal',
  4. qty: 25,
  5. size: { h: 14, w: 21, uom: 'cm' },
  6. status: 'A'
  7. },
  8. {
  9. item: 'notebook',
  10. qty: 50,
  11. size: { h: 8.5, w: 11, uom: 'in' },
  12. status: 'P'
  13. },
  14. {
  15. item: 'paper',
  16. qty: 100,
  17. size: { h: 8.5, w: 11, uom: 'in' },
  18. status: 'D'
  19. },
  20. {
  21. item: 'planner',
  22. qty: 75,
  23. size: { h: 22.85, w: 30, uom: 'cm' },
  24. status: 'D'
  25. },
  26. {
  27. item: 'postcard',
  28. qty: 45,
  29. size: { h: 10, w: 15.25, uom: 'cm' },
  30. status: 'A'
  31. }
  32. ]);
  1. $insertManyResult = $db->inventory->insertMany([
  2. [
  3. 'item' => 'journal',
  4. 'qty' => 25,
  5. 'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
  6. 'status' => 'A',
  7. ],
  8. [
  9. 'item' => 'notebook',
  10. 'qty' => 50,
  11. 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
  12. 'status' => 'P',
  13. ],
  14. [
  15. 'item' => 'paper',
  16. 'qty' => 100,
  17. 'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
  18. 'status' => 'D',
  19. ],
  20. [
  21. 'item' => 'planner',
  22. 'qty' => 75,
  23. 'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'],
  24. 'status' => 'D',
  25. ],
  26. [
  27. 'item' => 'postcard',
  28. 'qty' => 45,
  29. 'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'],
  30. 'status' => 'A',
  31. ],
  32. ]);
  1. await db.inventory.insert_many([
  2. {"item": "journal",
  3. "qty": 25,
  4. "size": {"h": 14, "w": 21, "uom": "cm"},
  5. "status": "A"},
  6. {"item": "notebook",
  7. "qty": 50,
  8. "size": {"h": 8.5, "w": 11, "uom": "in"},
  9. "status": "P"},
  10. {"item": "paper",
  11. "qty": 100,
  12. "size": {"h": 8.5, "w": 11, "uom": "in"},
  13. "status": "D"},
  14. {"item": "planner",
  15. "qty": 75,
  16. "size": {"h": 22.85, "w": 30, "uom": "cm"},
  17. "status": "D"},
  18. {"item": "postcard",
  19. "qty": 45,
  20. "size": {"h": 10, "w": 15.25, "uom": "cm"},
  21. "status": "A"}])
  1. Publisher<Success> insertManyPublisher = collection.insertMany(asList(
  2. Document.parse("{ item: 'journal', qty: 25, size: { h: 14, w: 21, uom: 'cm' }, status: 'A' }"),
  3. Document.parse("{ item: 'notebook', qty: 50, size: { h: 8.5, w: 11, uom: 'in' }, status: 'A' }"),
  4. Document.parse("{ item: 'paper', qty: 100, size: { h: 8.5, w: 11, uom: 'in' }, status: 'D' }"),
  5. Document.parse("{ item: 'planner', qty: 75, size: { h: 22.85, w: 30, uom: 'cm' }, status: 'D' }"),
  6. Document.parse("{ item: 'postcard', qty: 45, size: { h: 10, w: 15.25, uom: 'cm' }, status: 'A' }")
  7. ));
  1. var documents = new[]
  2. {
  3. new BsonDocument
  4. {
  5. { "item", "journal" },
  6. { "qty", 25 },
  7. { "size", new BsonDocument { { "h", 14 }, { "w", 21 }, { "uom", "cm" } } },
  8. { "status", "A" }
  9. },
  10. new BsonDocument
  11. {
  12. { "item", "notebook" },
  13. { "qty", 50 },
  14. { "size", new BsonDocument { { "h", 8.5 }, { "w", 11 }, { "uom", "in" } } },
  15. { "status", "P" }
  16. },
  17. new BsonDocument
  18. {
  19. { "item", "paper" },
  20. { "qty", 100 },
  21. { "size", new BsonDocument { { "h", 8.5 }, { "w", 11 }, { "uom", "in" } } },
  22. { "status", "D" }
  23. },
  24. new BsonDocument
  25. {
  26. { "item", "planner" },
  27. { "qty", 75 },
  28. { "size", new BsonDocument { { "h", 22.85 }, { "w", 30 }, { "uom", "cm" } } },
  29. { "status", "D" }
  30. },
  31. new BsonDocument
  32. {
  33. { "item", "postcard" },
  34. { "qty", 45 },
  35. { "size", new BsonDocument { { "h", 10 }, { "w", 15.25 }, { "uom", "cm" } } },
  36. { "status", "A" }
  37. }
  38. };
  39. collection.InsertMany(documents);
  1. $db->coll("inventory")->insert_many(
  2. [
  3. {
  4. item => "journal",
  5. qty => 25,
  6. size => { h => 14, w => 21, uom => "cm" },
  7. status => "A"
  8. },
  9. {
  10. item => "notebook",
  11. qty => 50,
  12. size => { h => 8.5, w => 11, uom => "in" },
  13. status => "P"
  14. },
  15. {
  16. item => "paper",
  17. qty => 100,
  18. size => { h => 8.5, w => 11, uom => "in" },
  19. status => "D"
  20. },
  21. {
  22. item => "planner",
  23. qty => 75,
  24. size => { h => 22.85, w => 30, uom => "cm" },
  25. status => "D"
  26. },
  27. {
  28. item => "postcard",
  29. qty => 45,
  30. size => { h => 10, w => 15.25, uom => "cm" },
  31. status => "A"
  32. }
  33. ]
  34. );
  1. client[:inventory].insert_many([
  2. { item: 'journal',
  3. qty: 25,
  4. size: { h: 14, w: 21, uom: 'cm' },
  5. status: 'A' },
  6. { item: 'notebook',
  7. qty: 50,
  8. size: { h: 8.5, w: 11, uom: 'in' },
  9. status: 'P' },
  10. { item: 'paper',
  11. qty: 100,
  12. size: { h: 8.5, w: 11, uom: 'in' },
  13. status: 'D' },
  14. { item: 'planner',
  15. qty: 75,
  16. size: { h: 22.85, w: 30, uom: 'cm' },
  17. status: 'D' },
  18. { item: 'postcard',
  19. qty: 45,
  20. size: { h: 10, w: 15.25, uom: 'cm' },
  21. status: 'A' },
  22. ])
  1. collection.insertMany(Seq(
  2. Document("""{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" }"""),
  3. Document("""{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "A" }"""),
  4. Document("""{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" }"""),
  5. Document("""{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" }"""),
  6. Document("""{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }""")
  7. )).execute()
  1. docs := []interface{}{
  2. bson.D{
  3. {"item", "journal"},
  4. {"qty", 25},
  5. {"size", bson.D{
  6. {"h", 14},
  7. {"w", 21},
  8. {"uom", "cm"},
  9. }},
  10. {"status", "A"},
  11. },
  12. bson.D{
  13. {"item", "notebook"},
  14. {"qty", 50},
  15. {"size", bson.D{
  16. {"h", 8.5},
  17. {"w", 11},
  18. {"uom", "in"},
  19. }},
  20. {"status", "P"},
  21. },
  22. bson.D{
  23. {"item", "paper"},
  24. {"qty", 100},
  25. {"size", bson.D{
  26. {"h", 8.5},
  27. {"w", 11},
  28. {"uom", "in"},
  29. }},
  30. {"status", "D"},
  31. },
  32. bson.D{
  33. {"item", "planner"},
  34. {"qty", 75},
  35. {"size", bson.D{
  36. {"h", 22.85},
  37. {"w", 30},
  38. {"uom", "cm"},
  39. }},
  40. {"status", "D"},
  41. },
  42. bson.D{
  43. {"item", "postcard"},
  44. {"qty", 45},
  45. {"size", bson.D{
  46. {"h", 10},
  47. {"w", 15.25},
  48. {"uom", "cm"},
  49. }},
  50. {"status", "A"},
  51. },
  52. }
  53.  
  54. 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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

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 inventorycollection:

  • Mongo Shell
  • Python
  • Java (Sync)
  • Node.js
  • PHP
  • Other
    • Motor
    • Java (Async)
    • C#
    • Perl
    • Ruby
    • Scala
    • Go
  1. db.inventory.deleteMany({})
  1. db.inventory.delete_many({})
  1. collection.deleteMany(new Document());
  1. await db.collection('inventory').deleteMany({});
  1. $deleteResult = $db->inventory->deleteMany([]);
  1. await db.inventory.delete_many({})
  1. Publisher<DeleteResult> deleteManyPublisher = collection.deleteMany(new Document());
  1. var filter = Builders<BsonDocument>.Filter.Empty;
  2. var result = collection.DeleteMany(filter);
  1. $db->coll("inventory")->delete_many( {} );
  1. client[:inventory].delete_many({})
  1. collection.deleteMany(Document()).execute()
  1. 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.deletedCountproperty contains the number of documents that matched thefilter.

Upon successful execution, thedeleteMany()method returns an instance ofMongoDB\DeleteResultwhose 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection 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:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. [ <field1> => <value1>, ... ]

To specify equality conditions, use <field>:<value>expressions in thequery filter document:

  1. { <field1>: <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq method to create thequery filter document:

  1. and(eq( <field1>, <value1>), eq( <field2>, <value2>) ...)

To specify equality conditions, construct a filter using theEq method:

  1. Builders<BsonDocument>.Filter.Eq(<field>, <value>);

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use <field> => <value>expressions in thequery filter document:

  1. { <field1> => <value1>, ... }

To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_ method to create thequery filter document:

  1. 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:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. and(gte(<field1>, <value1>), lt(<field2>, <value2>), eq(<field3>, <value3>))

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1>: { <operator1>: <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. [ <field1> => [ <operator1> => <value1> ], ... ]

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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:

  1. var builder = Builders<BsonDocument>.Filter;
  2. builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <field1> => { <operator1> => <value1> }, ... }

A query filter document canuse the query operators to specifyconditions in the following form:

  1. { <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:

  1. 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 inventorycollection where the status field equals "A":

  • Mongo Shell
  • Python
  • Java (Sync)
  • Node.js
  • PHP
  • Other
    • Motor
    • Java (Async)
    • C#
    • Perl
    • Ruby
    • Scala
    • Go
  1. db.inventory.deleteMany({ status : "A" })
  1. db.inventory.delete_many({"status": "A"})
  1. collection.deleteMany(eq("status", "A"));
  1. await db.collection('inventory').deleteMany({ status: 'A' });
  1. $deleteResult = $db->inventory->deleteMany(['status' => 'A']);
  1. await db.inventory.delete_many({"status": "A"})
  1. deleteManyPublisher = collection.deleteMany(eq("status", "A"));
  1. var filter = Builders<BsonDocument>.Filter.Eq("status", "A");
  2. var result = collection.DeleteMany(filter);
  1. $db->coll("inventory")->delete_many( { status => "A" } );
  1. client[:inventory].delete_many(status: 'A')
  1. collection.deleteMany(equal("status", "A")).execute()
  1. result, err := coll.DeleteMany(
  2. context.Background(),
  3. bson.D{
  4. {"status", "A"},
  5. },
  6. )
  • 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.deletedCountproperty contains the number of documents that matched thefilter.

Upon successful execution, thedeleteMany()method returns an instance ofMongoDB\DeleteResultwhose 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
  1. db.inventory.deleteOne( { status: "D" } )
  • Click the Table button in the top navigationto access the Table View:

../../_images/compass-table-btn-click-2.png

  • Use the Compass query bar tolocate the target document.

Copy the following filter document into the query bar and clickFind:

  1. { item: "paper" }

../../_images/compass-delete-paper-find.png

  • Hover over the document and click the trash icon whichappears on the right-hand side:

../../_images/compass-delete-button-click.png

After clicking the delete button, the document is flaggedfor deletion and Compass asks for confirmation that youwant to remove the document:

../../_images/compass-delete-confirm.png

  • Click Delete to confirm. Compass deletes thedocument from the collection.
  1. db.inventory.delete_one({"status": "D"})
  1. collection.deleteOne(eq("status", "D"));
  1. await db.collection('inventory').deleteOne({ status: 'D' });
  1. $deleteResult = $db->inventory->deleteOne(['status' => 'D']);
  1. await db.inventory.delete_one({"status": "D"})
  1. Publisher<DeleteResult> deleteOnePublisher = collection.deleteOne(eq("status", "D"));
  1. var filter = Builders<BsonDocument>.Filter.Eq("status", "D");
  2. var result = collection.DeleteOne(filter);
  1. $db->coll("inventory")->delete_one( { status => "D" } );
  1. client[:inventory].delete_one(status: 'D')
  1. collection.deleteOne(equal("status", "D")).execute()
  1. result, err := coll.DeleteOne(
  2. context.Background(),
  3. bson.D{
  4. {"status", "D"},
  5. },
  6. )

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

See also

See also

See also

See also

See also

See also

See also

See also

See also

See also