Bulk Write - Part 1
Learn and practice bulk write queries for different operations, such as insertOne, updateOne, updateMany.
We'll cover the following...
What is bulkWrite
?
MongoDB provides a bulkWrite
function to perform write-operations in bulk. In a write-operation, we individually perform create, update and delete operations… Instead, we can use the bulkWrite
function to perform all these operations together.
bulkWrite command syntax
Syntax of the bulkWrite
function:
db.<collection-name>.bulkWrite(
[ <operation 1>, <operation 2>, ... ],
{
writeConcern : <document>,
ordered : <boolean>
}
)
The first argument is an array of operations. The bulkWrite
method can execute multiple operations through one command, including create, update or delete operation.
Bulk write operations
Here’s is the list of all the bulkWrite
Below is the list of all the bulkWrite
operations:
insertOne
: Inserts one documentupdateOne
: Updates one document as per provided filtersupdateMany
: Updates multiple documents as per provided filterdeleteOne
: Removes one documentdeleteMany
: