在单个查询中从 mongo 中删除多个文档 [英] Remove multiple documents from mongo in a single query
本文介绍了在单个查询中从 mongo 中删除多个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要删除的 mongo '_id' 列表.目前我正在这样做
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:
db.users.remove({'_id' : item})
但我的问题是列表太大了......(可能会超过 100,000).所以查询列表中的每一项只会增加服务器的负载.是他们在 mongo 查询中传递整个列表的一种方式,这样我就不必一次又一次地触发查询.
but my problem is the list is too huge... (it might go 100,000 +). So querying for every item in list will only increase the load on server. Is their a way to pass the entire list in mongo query so that I dont have to fire query again and again.
谢谢
推荐答案
db.users.deleteMany({'_id':{'$in':inactive_users}})
这篇关于在单个查询中从 mongo 中删除多个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文