[SOLVED] Latest Mongo Driver Breaks Bulk Remove

In Meteor 1.10.2 and its mongo driver I could call the following bulk op code:

let bulkItemRemove = Items.rawCollection().initializeUnorderedBulkOp();
bulkItemRemove.find({_id: {$in: ids}}).remove();

I use a bulk remove because it can be millions of documents.

On Meteor 2.7.1 and the latest mongo driver, I get an error on the line where I try to call .remove() saying TypeError: bulkVoteRemove.find(...).remove is not a function. It still happens if I break the line into two lines as well.

I checked the changelog’s advice about the mongo docs and migrating but I didn’t see anything specifically about bulk operations.

My app has many other rawCollection bulk inserts and updates that work fine.


I saw some warnings too. Have you try deleteMany function? https://www.mongodb.com/docs/manual/reference/method/db.collection.deleteMany/#mongodb-method-db.collection.deleteMany

I haven’t, but that’s not a bulk operation right?. We ran into some kind of memory error I think on certain tests when we tried the regular Mongo .remove() for millions of documents.

1 Like

You’re right. deleteMany is not a bulk operation. I found an article, hopefully it will help: How to delete large amounts of data gracefully in mongodb

I needed to update the .remove() to .delete(). Thanks @rjdavid for the doc reference. Assuming this was due to the above linked Meteor 2.6 migration advice.

Scratching my head still, as I thought calling Collection.rawCollection() meant Mongo documentation like this on Bulk.find().remove() would work. The doc says that is Mongo 5.0 application code. But it sounds like Collection.rawCollection() gets you to the Node Mongo driver API… not the full Mongo database API? :thinking:

Yes, it does since we are running a node app.

1 Like