{ "_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"}
如何在mongodb中删除多个ID?
答案 0 :(得分:26)
为每个ID运行一次删除,或者使用in:
db.collection.remove( { _id : { $in: [
ObjectId("51ee3966e4b056fe8f074f48"),
ObjectId("51ee3966e4b056fe8f074f4a"),
ObjectId("51ee3966e4b056fe8f074f4b")
] } } );
答案 1 :(得分:0)
您可以使用命令deleteMany完成此操作。
const objects = [
ObjectId("51ee3966e4b056fe8f074f48"),
ObjectId("51ee3966e4b056fe8f074f4a"),
ObjectId("51ee3966e4b056fe8f074f4b")
];
db.collection.deleteMany({_id: { $in: objects}});