I would like to remove a large number of old documents from one collection, and therefore it makes sense to use an api array. Removing them is as simple as:
var bulk = db.myCollection.initializeUnorderedBulkOp();
bulk.find({
_id: {
$lt: oldestAllowedId
}
}).remove();
bulk.execute();
The only problem is trying to delete every document that meets these criteria, and in this case it’s millions of documents, so for performance reasons I don’t want to delete them right away. I want to use a constraint for an operation so that I can do something like this bulk.limit(10000).execute();and run through the operations for a few seconds to prevent the database from being locked for longer than necessary. However, I could not find any parameters that could be passed in bulk to limit the number that it executes.
Is there a way to limit mass operations this way?
- , , 1000 , , . , .