Navigation
This version of the documentation is archived and no longer supported.

Delete Documents

This page provides examples of delete operations using the following methods in the mongo shell:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of deleting documents using MongoDB Compass.

Populate the inventory collection with the following documents:

This page provides examples of delete operations using the following methods in the PyMongo Python driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the Java Synchronous Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the MongoDB Node.js Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the MongoDB PHP Library:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the Motor driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the Java Reactive Streams Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the MongoDB C# Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the MongoDB Perl Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the MongoDB Ruby Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

This page provides examples of delete operations using the following methods in the MongoDB Scala Driver:

The examples on this page use the inventory collection. To populate the inventory collection, run the following:

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" },
] );
[
   { 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, see Insert Documents.

Note

For complete reference on inserting documents in MongoDB Compass, see the Compass 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()

Delete All Documents

To delete all documents from a collection, pass an empty filter document {} to the db.collection.deleteMany() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter document {} to the pymongo.collection.Collection.delete_many() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty org.bson.Document object as the filter to the com.mongodb.client.MongoCollection.deleteMany method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter document {} to the Collection.deleteMany() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter document [] to the MongoDB\Collection::deleteMany() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter document {} to the motor.motor_asyncio.AsyncIOMotorCollection.delete_many() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty org.bson.Document object as the filter to the com.mongodb.reactivestreams.client.MongoCollection.deleteMany method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter Builders<BsonDocument>.Filter.Empty to the IMongoCollection.DeleteMany() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter document {} to the MongoDB::Collection::delete_many() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter document {} to the Mongo::Collection#delete_many() method.

The following example deletes all documents from the inventory collection:

Delete All Documents

To delete all documents from a collection, pass an empty filter Document() to the collection.deleteMany() method.

The following example deletes all documents from the inventory collection:

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()

The method returns a document with the status of the operation. For more information and examples, see deleteMany().

The delete_many() method returns an instance of pymongo.results.DeleteResult with the status of the operation.

The com.mongodb.client.MongoCollection.deleteMany method returns an instance of com.mongodb.client.result.DeleteResult with the status of the operation.

deleteMany() returns a promise that provides a result. The result.deletedCount property contains the number of documents that matched the filter.

Upon successful execution, the deleteMany() method returns an instance of MongoDB\DeleteResult whose getDeletedCount() method returns the number of documents that matched the filter.

The delete_many() coroutine asynchronously returns an instance of pymongo.results.DeleteResult with the status of the operation.

com.mongodb.reactivestreams.client.MongoCollection.deleteMany returns a Publisher object of type com.mongodb.client.result.DeleteResult if successful. Returns an instance of com.mongodb.MongoException if unsuccessful.

Upon successful execution, the IMongoCollection.DeleteMany() method returns an instance of DeleteResult whose DeletedCount property contains the number of documents that matched the filter.

Upon successful execution, the delete_many() method returns an instance of MongoDB::DeleteResult whose deleted_count attribute contains the number of documents that matched the filter.

Upon successful execution, the delete_many() method returns an instance of Mongo::Operation::Result, whose deleted_count attribute contains the number of documents that matched the filter.

Upon successful execution, the collection.deleteMany() method returns an Observable with a single element with a DeleteResult type parameter or with an com.mongodb.MongoException.

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the delete_many() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the com.mongodb.client.MongoCollection.deleteMany method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the delete_many() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the com.mongodb.reactivestreams.client.MongoCollection.deleteMany method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the IMongoCollection.DeleteMany() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the delete_many() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the delete_many() method.

The following example removes all documents from the inventory collection where the status field equals "A":

Delete All Documents that Match a Condition

You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

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

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

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq method to create the query filter document:

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

To specify equality conditions, construct a filter using the Eq method:

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

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

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

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

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

To specify equality conditions, use the com.mongodb.client.model.Filters.eq_ method to create the query filter document:

and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. For example:

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

In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use the FilterDefinitionBuilder methods to create a filter document. For example:

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

A query filter document can use the query operators to specify conditions in the following form:

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

A query filter document can use the query operators to specify conditions in the following form:

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

In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use the com.mongodb.client.model.Filters_ helper methods to facilitate the creation of filter documents. For example:

and(gte(<field1>, <value1>), lt(<field2>, <value2>), equal(<field3>, <value3>))

To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.

The following example removes all documents from the inventory collection where the status field equals "A":

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()

The method returns a document with the status of the operation. For more information and examples, see deleteMany().

The delete_many() method returns an instance of pymongo.results.DeleteResult with the status of the operation.

The com.mongodb.client.MongoCollection.deleteMany method returns an instance of com.mongodb.client.result.DeleteResult with the status of the operation.

deleteMany() returns a promise that provides a result. The result.deletedCount property contains the number of documents that matched the filter.

Upon successful execution, the deleteMany() method returns an instance of MongoDB\DeleteResult whose getDeletedCount() method returns the number of documents that matched the filter.

The delete_many() coroutine asynchronously returns an instance of pymongo.results.DeleteResult with the status of the operation.

com.mongodb.reactivestreams.client.MongoCollection.deleteMany returns a Publisher object of type com.mongodb.client.result.DeleteResult if successful. Returns an instance of com.mongodb.MongoException if unsuccessful.

Upon successful execution, the IMongoCollection.DeleteMany() method returns an instance of DeleteResult whose DeletedCount property contains the number of documents that matched the filter.

Upon successful execution, the delete_many() method returns an instance of MongoDB::DeleteResult whose deleted_count attribute contains the number of documents that matched the filter.

Upon successful execution, the delete_many() method returns an instance of Mongo::Operation::Result, whose deleted_count attribute contains the number of documents that matched the filter.

Upon successful execution, the collection.deleteMany() method returns an Observable with a single element with a DeleteResult type parameter or with an com.mongodb.MongoException.

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the db.collection.deleteOne() method.

The following example deletes the first document where status is "D":

Delete a Single Document

MongoDB Compass provides a simple way to delete a document from a collection. The following example shows how to delete the document with item equal to paper from the inventory collection:

Note

In this example we are using the Compass Table View to delete the document. The deletion process using the Compass List View follows a very similar approach.

For more information on the differences between Table View and List View in Compass, refer to the Compass documentation.

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the pymongo.collection.Collection.delete_one() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the com.mongodb.client.MongoCollection.deleteOne method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the Collection.deleteOne() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the MongoDB\Collection::deleteOne() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the motor.motor_asyncio.AsyncIOMotorCollection.delete_one() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the com.mongodb.reactivestreams.client.MongoCollection.deleteMany method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the IMongoCollection.DeleteOne() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the MongoDB::Collection::delete_one() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the Mongo::Collection#delete_one() method.

The following example deletes the first document where status is "D":

Delete Only One Document that Matches a Condition

To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the collection.deleteOne() method.

The following example deletes the first document where status is "D":

db.inventory.deleteOne( { status: "D" } )
  1. Click the Table button in the top navigation to access the Table View:

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

  2. Use the Compass query bar to locate the target document.

    Copy the following filter document into the query bar and click Find:

    { item: "paper" }
    
    ../../_images/compass-delete-paper-find.png

  3. Hover over the document and click the trash icon which appears on the right-hand side:


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

    After clicking the delete button, the document is flagged for deletion and Compass asks for confirmation that you want to remove the document:


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

  4. Click Delete to confirm. Compass deletes the document 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()

Delete Behavior

Indexes

Delete operations do not drop indexes, even if deleting all documents from a collection.

Atomicity

All write operations in MongoDB are atomic on the level of a single document. For more information on MongoDB and atomicity, see Atomicity and Transactions.