在单个查询中从mongo中删除多个文档 [英] Remove multiple documents from mongo in a single query

查看:80
本文介绍了在单个查询中从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.remove({'_id':{'$in':inactive_users}})

这篇关于在单个查询中从mongo中删除多个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆