Reputation: 341
I wanted to do a bulkwrite on my MongoDb, the Collection on which I am using the bulkwrite is very simple.
What I am not sure about is weather it would be right for me to use bulkwrite. I have the following questions:
1) One if I do a bulkwrite operation is it atomic?
2) Will bulkwrite write do all the updates simultaniously or can there be delays between the writes?
bulkArr.push({
updateOne: {
"filter": { "_id": input[i].variantId },
"update": { $inc: { "stocks": -quant } }
}
});
Upvotes: 4
Views: 3145
Reputation: 3529
bulkwrite
operation, is it atomic?
From the docs
updateMany()
or bulkWrite()
) modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic.Will bulkwrite
write do all the updates simultaneously?
Not really, The { ordered : false/true }
parameter specifies
whether bulkWrite()
will execute operations in order or not. By
default, operations are executed in order.
docs
Also in bulkWrite()
operations of the same type (e.g. multiple
inserts) may be grouped together and sent to the server, Which
happens in batch sizes not exceeding 100,000 writes.
Upvotes: 3