【发布时间】:2019-02-04 22:41:53
【问题描述】:
我有这样的 Mongoose 架构:
{
......
project: [
{
Name: String,
Criteria:[
{
criteriaName:String,
}
]
}
]
......
}
我想根据对象 id 删除项目数组中的条件数组对象之一
我尝试了以下代码
criteria.findOneAndUpdate({
"_id": uid,
},{ $pull: { "project.Criteria": { _id: cid } } }, (err) => {
......
}
但是这行不通,它说“不能使用(project.Criteria)的部分(Criteria)来遍历元素”
【问题讨论】:
-
必须是
{ $pull: { "project.$.Criteria": { _id: cid } } } -
@AnthonyWinzlet 上面说的是
The positional operator did not find the match needed from the query.不知道能不能在数组数组中工作 -
你的mongodb版本是多少?