【发布时间】:2020-09-03 05:39:06
【问题描述】:
如何使用聚合删除集合中所有记录的特定值:
收集数据:
[
{
_id: "bmasndvhjbcw",
name: "lucas",
occupation: "scientist",
present_working:true,
age: 55,
location: "texas"
},
{
_id: "bmasndvhjbcx",
name: "mark",
occupation: "scientist",
age: 45,
present_working:false,
location: "texas"
},
{
_id: "bmasndvhjbcq",
name: "cooper",
occupation: "physicist",
age: 69,
location: "texas",
present_working:false
}
]
删除记录中存在present_working:false 的行。数据库中的数据不需要删除,只需要在聚合管道中修改即可
仅删除 present_working:false 和 present_working:false 后的预期输出应保留在数据库中。 :
[
{
_id: "bmasndvhjbcw",
name: "lucas",
occupation: "scientist",
present_working:true,
age: 55,
location: "texas"
},
{
_id: "bmasndvhjbcx",
name: "mark",
occupation: "scientist",
age: 45,
location: "texas"
},
{
_id: "bmasndvhjbcq",
name: "cooper",
occupation: "physicist",
age: 69,
location: "texas"
}
]
MongoDB 版本:4.0
【问题讨论】:
标签: mongodb aggregation-framework aggregate aggregate-functions aggregation