【发布时间】:2016-07-12 16:27:23
【问题描述】:
我在 mongodb 中有一个文档,其中包含我需要更新的 2 级深度嵌套对象数组,就像这样。
{
"id":12362,
"onGoing":[
{
"id":14597,
"offers":[
{
"id":56897,
"status":"validated"
},
{
"id":86127,
"status":"validated"
}
]
},
{
"id":89451,
"offers":[
{
"id":12235,
"status":"validated"
},
{
"id":56457,
"status":"validated"
}
]
}
]
}
我想更新与其 ID 匹配的所有优惠。
我已经尝试更新了
db.repairJobs.update({
"onGoing.offers":{
$elemMatch:{
_id:{
$in:[
'56897', '56457'
]
}
}
}
},
{
$set:{
"ongoing.offers.$.status":"ACCEPTED"
}
});
但是报错:不能使用部分(ongoing of progress.offers.0.status)来遍历元素({ongoing: [ { _id: null, ...
有什么方法可以更新,解决方案需要兼容spring Data。
【问题讨论】: