Delete Documents (original) (raw)
You can delete documents in MongoDB using the following methods:
- Your programming language's driver.
- The MongoDB Atlas UI. To learn more, seeDelete a Document with MongoDB Atlas.
- MongoDB Compass.
➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples or select MongoDB Compass.
This page uses MongoDB Compass to delete the documents.
Populate the inventory
collection with the following documents:
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, seeInsert Documents.
mongoc_collection_t *collection;
mongoc_bulk_operation_t *bulk;
bson_t *doc;
bool r;
bson_error_t error;
bson_t reply;
collection = mongoc_database_get_collection (db, "inventory");
bulk = mongoc_collection_create_bulk_operation_with_opts (collection, NULL);
doc = BCON_NEW (
"item", BCON_UTF8 ("journal"),
"qty", BCON_INT64 (25),
"size", "{",
"h", BCON_DOUBLE (14),
"w", BCON_DOUBLE (21),
"uom", BCON_UTF8 ("cm"),
"}",
"status", BCON_UTF8 ("A"));
r = mongoc_bulk_operation_insert_with_opts (bulk, doc, NULL, &error);
bson_destroy (doc);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
doc = BCON_NEW (
"item", BCON_UTF8 ("notebook"),
"qty", BCON_INT64 (50),
"size", "{",
"h", BCON_DOUBLE (8.5),
"w", BCON_DOUBLE (11),
"uom", BCON_UTF8 ("in"),
"}",
"status", BCON_UTF8 ("P"));
r = mongoc_bulk_operation_insert_with_opts (bulk, doc, NULL, &error);
bson_destroy (doc);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
doc = BCON_NEW (
"item", BCON_UTF8 ("paper"),
"qty", BCON_INT64 (100),
"size", "{",
"h", BCON_DOUBLE (8.5),
"w", BCON_DOUBLE (11),
"uom", BCON_UTF8 ("in"),
"}",
"status", BCON_UTF8 ("D"));
r = mongoc_bulk_operation_insert_with_opts (bulk, doc, NULL, &error);
bson_destroy (doc);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
doc = BCON_NEW (
"item", BCON_UTF8 ("planner"),
"qty", BCON_INT64 (75),
"size", "{",
"h", BCON_DOUBLE (22.85),
"w", BCON_DOUBLE (30),
"uom", BCON_UTF8 ("cm"),
"}",
"status", BCON_UTF8 ("D"));
r = mongoc_bulk_operation_insert_with_opts (bulk, doc, NULL, &error);
bson_destroy (doc);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
doc = BCON_NEW (
"item", BCON_UTF8 ("postcard"),
"qty", BCON_INT64 (45),
"size", "{",
"h", BCON_DOUBLE (10),
"w", BCON_DOUBLE (15.25),
"uom", BCON_UTF8 ("cm"),
"}",
"status", BCON_UTF8 ("A"));
r = mongoc_bulk_operation_insert_with_opts (bulk, doc, NULL, &error);
bson_destroy (doc);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
/* "reply" is initialized on success or error */
r = (bool) mongoc_bulk_operation_execute (bulk, &reply, &error);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
}
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);
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' }")
));
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.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",
},
]
)
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'
}
]);
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mi>n</mi><mi>s</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>M</mi><mi>a</mi><mi>n</mi><mi>y</mi><mi>R</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">insertManyResult = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.02778em;">ser</span><span class="mord mathnormal" style="margin-right:0.10903em;">tM</span><span class="mord mathnormal">an</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">es</span><span class="mord mathnormal">u</span><span class="mord mathnormal">lt</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>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',
],
]);
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",
},
]
)
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()
To delete all documents from a collection, pass an emptyfilter document {}
to thedb.collection.deleteMany() method.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyfilter Builders<BsonDocument>.Filter.Empty
to theIMongoCollection.DeleteMany() method.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyfilter document to theCollection.DeleteMany function.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyBson
object as the filter to theMongoCollection.deleteMany() method.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyfilter document {}
to theCollection.deleteMany()method.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyfilter document []
to theMongoDB\\Collection::deleteMany()method.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyfilter document {}
to theMongo::Collection#delete_many()method.
The following example deletes all documents from the inventory
collection:
To delete all documents from a collection, pass an emptyfilter Document()
to thecollection.deleteMany()method.
The following example deletes all documents from the inventory
collection:
db.inventory.deleteMany({})
mongoc_collection_t *collection;
bson_t *selector;
bool r;
bson_error_t error;
collection = mongoc_database_get_collection (db, "inventory");
selector = BCON_NEW (NULL);
r = mongoc_collection_delete_many (collection, selector, NULL, NULL, &error);
bson_destroy (selector);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
var filter = Builders<BsonDocument>.Filter.Empty;
var result = collection.DeleteMany(filter);
Publisher<DeleteResult> deleteManyPublisher = collection.deleteMany(new Document());
collection.deleteMany(new Document());
await db.inventory.delete_many({})
await db.collection('inventory').deleteMany({});
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>e</mi><mi>l</mi><mi>e</mi><mi>t</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">deleteResult = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">es</span><span class="mord mathnormal">u</span><span class="mord mathnormal">lt</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>db->inventory->deleteMany([]);
db.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, seedeleteMany().
The mongoc_collection_delete_manymethod returns true
if successful, or returns false
and sets an error if there are invalid arguments or a server or network error occurs.
Upon successful execution, theCollection.DeleteManyfunction returns an instance ofDeleteResult whoseDeletedCount
property contains the number of documents that matched the filter.
Collection.deleteMany()returns a promise that provides a result
. The result.deletedCount
property contains the number of documents that matched the filter.
Upon successful execution, thedelete_many() method returns an instance ofMongo::Operation::Result, whosedeleted_count
attribute contains the number of documents that matched the filter.
Upon successful execution, thecollection.deleteMany() method returns anObservablewith a single element with a DeleteResult
type parameter or with an com.mongodb.MongoException
.
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedeleteMany() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 themongoc_collection_tand a bson_tthat matches the documents to be deleted to themongoc_collection_delete_manymethod.
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to theIMongoCollection.DeleteMany()method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to theCollection.DeleteMany function.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thecom.mongodb.reactivestreams.client.MongoCollection.deleteManymethod.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thecom.mongodb.client.MongoCollection.deleteMany method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to theMongoCollection.deleteMany() method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedelete_manymethod.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedeleteMany()method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedeleteMany()method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedelete_many method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedelete_many()method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
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 thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, construct a filter using theEq method:
Builders<BsonDocument>.Filter.Eq(<field>, <value>);
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(eq(<field1>, <value1>), eq(<field2>, <value2>) ...)
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
[ <field1> => <value1>, ... ]
To specify equality conditions, use <field>:<value>
expressions in thequery filter document:
{ <field1>: <value1>, ... }
To specify equality conditions, use <field> => <value>
expressions in thequery filter document:
{ <field1> => <value1>, ... }
To specify equality conditions, use thecom.mongodb.client.model.Filters.eq_
method to create thequery filter document:
and(equal(<field1>, <value1>), equal(<field2>, <value2>) ...)
In addition to the equality filter, MongoDB provides various query operators to specify filter conditions. Use theFilterDefinitionBuildermethods to create a filter document. For example:
var builder = Builders<BsonDocument>.Filter;
builder.And(builder.Eq(<field1>, <value1>), builder.Lt(<field2>, <value2>));
In addition to the equality condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 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 condition, MongoDB provides various query operators to specify filter conditions. Use thecom.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 afilter parameter to thedeleteMany()method.
The following example removes all documents from the inventory
collection where the status
field equals "A"
:
db.inventory.deleteMany({ status : "A" })
mongoc_collection_t *collection;
bson_t *selector;
bool r;
bson_error_t error;
collection = mongoc_database_get_collection (db, "inventory");
selector = BCON_NEW ("status", BCON_UTF8 ("A"));
r = mongoc_collection_delete_many (collection, selector, NULL, NULL, &error);
bson_destroy (selector);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
var filter = Builders<BsonDocument>.Filter.Eq("status", "A");
var result = collection.DeleteMany(filter);
deleteManyPublisher = collection.deleteMany(eq("status", "A"));
collection.deleteMany(eq("status", "A"));
await db.inventory.delete_many({"status": "A"})
await db.collection('inventory').deleteMany({ status: 'A' });
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>e</mi><mi>l</mi><mi>e</mi><mi>t</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">deleteResult = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">es</span><span class="mord mathnormal">u</span><span class="mord mathnormal">lt</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>db->inventory->deleteMany(['status' => 'A']);
db.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, seedeleteMany().
The mongoc_collection_delete_manymethod returns true
if successful, or returns false
and sets an error if there are invalid arguments or a server or network error occurs.
Upon successful execution, theCollection.DeleteManyfunction returns an instance ofDeleteResult whoseDeletedCount
property contains the number of documents that matched the filter.
Collection.deleteMany()returns a promise that provides a result
. The result.deletedCount
property contains the number of documents that matched the filter.
Upon successful execution, thedelete_many() method returns an instance ofMongo::Operation::Result, whosedeleted_count
attribute contains the number of documents that matched the filter.
Upon successful execution, thecollection.deleteMany() method returns anObservablewith a single element with a DeleteResult
type parameter or with an com.mongodb.MongoException
.
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"
:
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 theinventory
collection:
Note
In this example we are using the CompassTable View to delete the document. The deletion process using the CompassList View follows a very similar approach.
For more information on the differences between Table View and List View in Compass, refer to theCompass documentation.
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use theIMongoCollection.DeleteOne()method.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use theCollection.DeleteOne function.
The following example deletes the first document where status
is"D"
:
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.deleteOnemethod.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter, even if multiple documents match the specified filter, you can use the MongoCollection.deleteOne()method.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use themotor.motor_asyncio.AsyncIOMotorCollection.delete_onemethod.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use theCollection.deleteOne()method.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use theMongoDB\\Collection::deleteOne()method.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use thepymongo.collection.Collection.delete_one method.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use theMongo::Collection#delete_one()method.
The following example deletes the first document where status
is"D"
:
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use thecollection.deleteOne()method.
The following example deletes the first document where status
is"D"
:
db.inventory.deleteOne( { status: "D" } )
- Click the Table button in the top navigation to access the Table View:
- Use the Compass query bar to locate the target document.
Copy the following filter document into the query bar and clickFind: - Hover over the document and click the trash icon which appears on the right-hand side:
After clicking the delete button, the document is flagged for deletion and Compass asks for confirmation that you want to remove the document: - Click Delete to confirm. Compass deletes the document from the collection.
mongoc_collection_t *collection;
bson_t *selector;
bool r;
bson_error_t error;
collection = mongoc_database_get_collection (db, "inventory");
selector = BCON_NEW ("status", BCON_UTF8 ("D"));
r = mongoc_collection_delete_one (collection, selector, NULL, NULL, &error);
bson_destroy (selector);
if (!r) {
MONGOC_ERROR ("%s\n", error.message);
goto done;
}
Be sure to also clean up any open resources by calling the following methods, as appropriate:
var filter = Builders<BsonDocument>.Filter.Eq("status", "D");
var result = collection.DeleteOne(filter);
Publisher<DeleteResult> deleteOnePublisher = collection.deleteOne(eq("status", "D"));
collection.deleteOne(eq("status", "D"));
await db.inventory.delete_one({"status": "D"})
await db.collection('inventory').deleteOne({ status: 'D' });
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>e</mi><mi>l</mi><mi>e</mi><mi>t</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">deleteResult = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">es</span><span class="mord mathnormal">u</span><span class="mord mathnormal">lt</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>db->inventory->deleteOne(['status' => 'D']);
db.inventory.delete_one({"status": "D"})
client[:inventory].delete_one(status: 'D')
collection.deleteOne(equal("status", "D")).execute()
Note
You can delete only one document at a time in the MongoDB Atlas UI. To delete multiple documents, connect to your Atlas deployment from mongosh or a MongoDB driver and follow the examples on this page for your preferred method.
The example in this section uses the sample movies dataset. To learn how to load the sample dataset into your MongoDB Atlas deployment, see Load Sample Data.
To delete a document in MongoDB Atlas, follow these steps:
Warning
Navigation Improvements In Progress
We're currently rolling out a new and improved navigation experience. If the following steps don't match your view in the Atlas UI, see the preview Atlas documentation.
If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it's not already displayed, select your project from the Projects menu in the navigation bar.
If it's not already displayed, click Clusters in the sidebar.
The Clusters page displays.For the cluster that contains the sample data, click Browse Collections.
In the left navigation pane, select the
sample_mflix
database.Select the
movies
collection.
Optionally, you can specify a query filter documentin the Filter field. A query filter document usesquery operators to specify search conditions.
Copy the following query filter document into theFilter search bar and click Apply:
{ genres: "Action", rated: { $in: [ "PG", "PG-13" ] } }
This query filter returns all documents in the sample_mflix.movies
collection where genres
equals Action
and rated
equals eitherPG
or PG-13
.
- For the document that you want to delete, hover over the document and click the trash icon that appears on the right-hand side.
After clicking the delete button, MongoDB Atlas flags the document for deletion and asks for your confirmation. - Click Delete to confirm your selection.
To learn more, see Create, View, Update, and Delete Documents.
Delete operations do not drop indexes, even if deleting all documents from a collection.
All write operations in MongoDB are atomic on the level of a single document. For more information on MongoDB and atomicity, seeAtomicity and Transactions.
With write concerns, you can specify the level of acknowledgment requested from MongoDB for write operations. For details, seeWrite Concern.
See also:
- com.mongodb.reactivestreams.client.MongoCollection.deleteMany
- com.mongodb.reactivestreams.client.MongoCollection.deleteOne
- Java Reactive Streams Driver Quick Tour
See also:
- com.mongodb.client.MongoCollection.deleteMany
- com.mongodb.client.MongoCollection.deleteOne
- Additional Java Synchronous Driver Write Examples
See also:
- MongoCollection.deleteOne()
- MongoCollection.deleteMany()
- Kotlin Coroutine Driver Delete Documents Guide
See also:
- motor.motor_asyncio.AsyncIOMotorCollection.delete_many
- motor.motor_asyncio.AsyncIOMotorCollection.delete_one
- Additional Methods
See also: