我有以下文件
{
"_id": "5c6eabcc813ea3fabf972eaa",
"employee_id": "abc",
"name": "singh",
"salary": 0
},
{
"_id": "5c6eabcc813ea3fabf972eaa",
"employee_id": "abc",
"name": "singh",
"salary": 0
},
{
"_id": "5c6eabcc813ea3fabf972eaa",
"employee_id": "abc",
"name": "singh",
"salary": {
"_id": "5c80ddc1ef020744825efe9c",
"month": 2,
"year": 2019
}
如果与上述数据集中给出的“ _id”值相同,如果salary.month不等于2,我想删除文档。我正在使用聚合管道。请帮助我。
谢谢。
答案 0 :(得分:0)
下面给出的查询可以为您完成
。db.getCollection('CollectionName').deleteMany({ $where : function() { return (this._id === this.salary._id && this.salary.month === 2) }})