HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Mongodb Bulk find and remove is taking long time

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
mongodbbulklongtimeremovefindandtaking

Problem

I'm just making my hands dirty(handson) with MongoDB. First I did bulk insert of 1 million documents.

// Bulk insert query
var bulk = db.bulktest.initializeUnorderedBulkOp();
for(var i=0;i<1000000;i++){bulk.insert({a:i});}
bulk.execute();


It took 10 seconds to insert all the document which is comparatively good. None of the documents were missed.

However, when it comes to bulk find and removal, the performance has drastically came down and is really bad as it is removing each document in the order of 10ms.

// find and removal bulk query
var bulk = db.bulktest.initializeUnorderedBulkOp();
for(var i=0;i<1000000;i++){bulk.find({a:i}).remove();}
bulk.execute();


Has anyone done tweaking around bulk removal ?

I've only one option to drop the complete collection and I don't want to do this.

Solution

This shouldn't have anything to do with bulk operations. The find operation must read through the collection, which takes time on 1million documents.

Adding an index on a should improve the speed dramatically.

Context

StackExchange Database Administrators Q#123329, answer score: 3

Revisions (0)

No revisions yet.