Remove multiple documents from mongo in a single query

后端 未结 5 877
栀梦
栀梦 2020-11-30 02:16

I have a list of mongo \'_id\' which I want to delete. Currently I am doing this

# inactive_users -->  list of inactive users 
for item in inactive_users:         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 03:02

    You need to pass the ids in a specific format using ObjectId():

    db.users.remove({_id: {$in: [ObjectId('Item1'), ObjectId('Item2'), ObjectId('Item2')]}});
    

    Remove doesn't accept integer - you have to use ObjectId instance with _id format as a string.

提交回复
热议问题