I am newbie to mongodb and would like to implement mongodb in my project having millions of record.Would like to know what should i prefer for update -bulk.find.update() vs update.collection with multi =true for performance.
As far as I know the biggest gains Bulk
provides are these:
Bulk operations send only one request to the MongoDB for the all requests in the bulk. Others send a request per document or send only for one operation type from one of insert
, update
, updateOne
, upsert
with update
operations and remove
.
Bulk can handle a lot of different cases at different lines on a code page.
Bulk operations can work as asynchronously. Others cannot.
But today some operations work bulk
based. For instance insertMany
.
If the gains above have taken into account, update()
must show the same performance results with an bulk.find.update()
operation.
Because update()
can take only one query object sending to MongoDB. And multi: true
is only an argument which specifies that the all matched documents have to be updated. This means it makes only one request on the network. Just like Bulk
operations.
So, both of sends only one request to MongoDB and MongoDB evaluates the query clause to find the documents that'd be updated then updates them!
I had tried to find out an answer for this question on MongoDB official site but I could not.
So, an explanation from @AsyaKamsky would be great!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With