Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bulk.find.update() vs update.collection(multi=true) in mongo

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.

like image 606
Varun Singh Avatar asked Feb 04 '16 15:02

Varun Singh


1 Answers

As far as I know the biggest gains Bulk provides are these:

  1. 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 .

  2. Bulk can handle a lot of different cases at different lines on a code page.

  3. 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!

like image 175
efkan Avatar answered Oct 04 '22 01:10

efkan