I'm running Mongo 2.6.3 I'm updating about 900 records, and sometimes up to 5000 records. I had this in a loop before, and for 900 records the upserts took about 1 minute to complete.
Right now, I'm using the initializeUnorderedBulkOp API and it's taking about 40 seconds for 900 records. Why is it so slow?
I basically have
var batch = collection.initializeUnorderedBulkOp({useLegacyOps: true});
// for loop
batch.find(query).upsert().updateOne({my object});
batch.execute({w:0},function(err, result) {
This is using the node driver. Screenshot of my network panel for these calls http://cl.ly/image/0L2a0o0w1I1b
When the data is smaller, it takes less time, so it's definitely a number of records problem. Lastly, my objects are not huge, they are maybe 9 keys or so, no big data.
Any ideas on how to get this time down?
Based on your comment, your find
query is not using an index which will prompt a full collection scan.
Add an index to your collection that can be used by find(query)
; use explain()
to confirm it's being used.