How to delete multiple ids in mongodb?

user1983299 picture user1983299 · Jul 24, 2013 · Viewed 11.8k times · Source
{ "_id" : ObjectId("51ee3966e4b056fe8f074f48"), "userid" : "66", "clientid" : "88", "deviceid" : "22", "timestamp" : "1374214822000"}
{ "_id" : ObjectId("51ee507ae4b056fe8f074f4a"), "userid" : "66", "clientid" : "88", "deviceid" : "22", "timestamp" : "1374214822000"}
{ "_id" : ObjectId("51ee51fee4b056fe8f074f4b"), "userid" : "66", "clientid" : "88", "deviceid" : "22", "timestamp" : "1374214822000"}

How to delete multiple ids in mongodb?

Answer

Derick picture Derick · Jul 24, 2013

By running remove once for each ID, or perhaps using in:

db.collection.remove( { _id : { $in: [
    ObjectId("51ee3966e4b056fe8f074f48"), 
    ObjectId("51ee3966e4b056fe8f074f4a"), 
    ObjectId("51ee3966e4b056fe8f074f4b") 
] } } );