MongoDB bulk update is slow

I am running Mongo 2.6.3 I am updating about 900 records and sometimes up to 5000 records. I used to have this in a loop and for 900 records the urastas took about 1 minute.

I am currently using the initializeUnorderedBulkOp API and it takes about 40 seconds for 900 records. Why is it so slow?

Basically I

var batch = collection.initializeUnorderedBulkOp({useLegacyOps: true});
// for loop
batch.find(query).upsert().updateOne({my object});
batch.execute({w:0},function(err, result) {

      

The node driver is used. Screenshot of my network bar for these calls http://cl.ly/image/0L2a0o0w1I1b

When there is less data, it takes less time, so definitely a problem with multiple entries. Finally, my objects are not huge, they can be 9 or so, no big data.

Any ideas on how to get this time?

+3


source to share


1 answer


Based on your comment, your query is find

not using an index which will ask for a full scan of the collection.



Add an index to your collection that can be used find(query)

; use explain()

to confirm its use.

+2


source







All Articles