Delete many documents at once from MongoDB

Hello, I have a little issue here while trying to delete many documents from many collections. I use:

Collection.remove({filter}, {}, {multi:true}) for like 8 collections. While processing it I get an error from each collection even though all of required documents being removed.

Exception in delivering result of invoking ‘/collection/remove’: TypeError: callback is not a function…

What would be the best way of deleting many documents from many collections at once? all documents are tied up to main _id which I use to filter. I guess new deleteMany() is not yet available in Meteor mongo api wrapper?

I20170120-11:12:48.651(0)? Exception in callback of async function: TypeError: callback is not a function
I20170120-11:12:48.651(0)?     at packages/mongo/collection.js:651:5
I20170120-11:12:48.652(0)?     at runWithEnvironment (packages/meteor.js:1176:24)
I20170120-11:12:48.653(0)?     at packages/meteor.js:1189:14
I20170120-11:12:48.653(0)?     at packages/mongo/mongo_driver.js:328:7
I20170120-11:12:48.654(0)?     at runWithEnvironment (packages/meteor.js:1176:24)

Thanks!

Edited:

Solved. Error was coming out because {multi:true} is not needed anymore…

Yeah, you need {multi:true} for update but not for remove.

1 Like

Hi there,

I’ve got this error too but i’m not using { mutli : true } in remove function for mongo…

Is there an other case when this error could appear ?

Thank you !

Mongo.Collection.remove takes only 2 args, use it like Collection.remove(selector, callback), i.e. Topics.remove({authorId}, (err) => {});