繁体   English   中英

如何在 MongoDB shell 中通过 $and 查询正确使用 deleteMany()?

[英]How do I properly use deleteMany() with an $and query in the MongoDB shell?

我正在尝试删除我的集合infrastructure结构中具有“管道”的type.primary属性和“oil”的type.secondary属性的所有文档。

我正在尝试使用以下查询: db.infrastructure.deleteMany({$and: [{"properties.type.primary": "pipelines"}, {"properties.type.secondary": "oil"}] }) ,

返回: { acknowledged: true, deletedCount: 0 }

我希望我的查询能够工作,因为在 MongoDB Compass 中,我可以检索 182 个与查询匹配的文档{$and: [{"properties.type.primary": "pipelines"}, {"properties.type.secondary": "oil"}] }

我的文档显示为以下结构(仅相关部分):

properties": {
                "optional": {
                    "description": ""
                },
                "original": {
                    "Opername": "ENBRIDGE",
                    "Pipename": "Lakehead",
                    "Shape_Leng": 604328.294581,
                    "Source": "EIA"
                },
                "required": {
                    "unit": null,
                    "viz_dim": null,
                    "years": []
                },
                "type": {
                    "primary": "pipelines",
                    "secondary": "oil"
                }
...

我的理解是我只需要将过滤器传递给deleteMany()并且$and需要一个对象数组。 由于某种原因,两者结合在这里不起作用。

我意识到最简单的答案是正确的——我拼错了我的数据库名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM