{ "_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?
To remove an element, update, and use $pull in MongoDB. The $pull operator removes from an existing array all instances of a value or values that match a specified condition.
The deleteMany() method returns an object that contains three fields: n – number of matched documents. ok – 1 if the operation was successful. deletedCount – number of deleted documents.
remove() The remove() method removes documents from the database. It can remove one or all documents from the collection that matches the given query expression.
By running remove once for each ID, or perhaps using in:
db.collection.remove( { _id : { $in: [ ObjectId("51ee3966e4b056fe8f074f48"), ObjectId("51ee3966e4b056fe8f074f4a"), ObjectId("51ee3966e4b056fe8f074f4b") ] } } );
You can accomplish this by using the command deleteMany.
const objects = [ ObjectId("51ee3966e4b056fe8f074f48"), ObjectId("51ee3966e4b056fe8f074f4a"), ObjectId("51ee3966e4b056fe8f074f4b") ]; db.collection.deleteMany({_id: { $in: objects}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With