在Python中删除多个MongoDB文档
您好,
我正在尝试使用以下语法从 MongoDB 集合中删除多个文档。我不知道这是否正确,因为我在互联网上的某个地方找到了它,并且自从强制执行此声明的合法性以来一直无法找到任何内容:
pymongo_collection_object.remove(
[
{
'sku': '100-00'
},
{
'sku': '200-00'
}
]
, safe=True)
我希望上面的代码会删除包括“sku”值的两个文档“100-00”或“200-00”,但不幸的是,这两个文档仍然存在于集合中。我还尝试将“sku”键及其值转换为 Unicode,因为我知道它们存储在这种编码中。正如您所知,我还启用了安全模式,以确保服务器端不会发生任何异常情况。
如有任何帮助,我们将不胜感激,谢谢!
Greetings,
I am attempting to remove multiple documents from a MongoDB collection using the following syntax. I don't know if this is correct as I found it somewhere on the internet and haven't been able to find anything since enforcing the legitimacy of this statement:
pymongo_collection_object.remove(
[
{
'sku': '100-00'
},
{
'sku': '200-00'
}
]
, safe=True)
I would expect the above code would remove both documents including a 'sku' value of '100-00' or '200-00' but unfortunately both documents are still present within the collection. I also tried casting both the 'sku' key and its value to Unicode as I know they are stored in this encoding. As you can tell I am also enabling safe mode ensuring that there is nothing out of line happening on the server side.
Any help is appreciated, thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 $ 或 / $in 运算符来执行此操作。
试试这个:
或者
You can do so by using $or / $in operators.
Try this:
or