Bulk Write: Part 2
Learn and practice bulk write queries for the deleteOne, deleteMany, replaceOne operations.
We'll cover the following...
We'll cover the following...
Bulk write operations
deleteOne
The deleteOne
operation is used to delete one document.
Syntax:
db.<collection-name>.bulkWrite([
{
deleteOne : {
"filter" : <document>,
"collation" : <document>
}
}
])
This function deletes the first document in the collection that matches the "filter" : <documents>
.
Below is an example of how to perform delete operations on the task
collection using bulkWrite
.
Press + to interact
db.tasks.bulkWrite([{deleteOne : {filter : {name: "Task 1"},}}])
This query returns the below output.
{
acknowledged: true,
insertedCount: 0,
insertedIds: {},
matchedCount: 0,
modifiedCount: 0,
**deletedCount: 1,**
upsertedCount: 0,
upsertedIds: {}
}
Here, the deleteCount:1
...