我正在尝试更新ducument的嵌套字段,但不知道为什么它没有成功。请帮忙。
我的文档结构如下:
{
"_id": {
"$oid": "594d173df36d285a33da90cf"
},
"available": 1,
"brand": [
{
"_id": {
"$oid": "59db10918bbe2316281d58d1"
},
"name": "test",
"createdby": "***************",
"createdon": "Mon Oct 09 2017 11:30:42 GMT+0530 (India Standard Time)",
"feedbacks": [
{
"_id": {
"$oid": "5a1039c25443604328ecf398"
},
"feedback": "hello",
"date": "Sat Nov 18 2017 19:16:36 GMT+0530 (India Standard Time)",
"reportedby": []
},
{
"_id": {
"$oid": "5a1039c25498504328ecf398"
},
"feedback": "hello",
"date": "Sat Nov 18 2017 19:16:36 GMT+0530 (India Standard Time)",
"reportedby": []
}
]
}
]
}
我的查询就像:
db.products.update({
'_id': mongojs.ObjectId(594d173df36d285a33da90cf),
'brand._id': mongojs.ObjectId(59db10918bbe2316281d58d1),
'brand.feedbacks._id': mongojs.ObjectId(5a1039c25498504328ecf398),
}, {
$addToSet: { 'brand.feedbacks.reportedby': skillSet.userId }
},
function(err, products) {
})
错误如下: {n:0, nModified:0, OPTIME: {ts:时间戳{ bsontype:'时间戳',低:1,high_:1512829477}, t:5}, electionId:7fffffff0000000000000005, 好的:1}
答案 0 :(得分:0)
您可以尝试以下查询:
{brand:{$addToSet:{'feedbacks.reportedly':'skillset.userId}}}