mongojs更新mongodb中的嵌套数组元素

问题描述 投票:0回答:1

我正在尝试更新文档的嵌套字段,但不要为什么它没有成功。请帮忙。

我的文档结构如下:

{
    "_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:Timestamp {bsontype:'Timestamp',low:1,high_:1512829477},t:5},electionId:7fffffff0000000000000005,ok:1}

node.js mongodb mongojs
1个回答
0
投票

您可以尝试以下查询:

{brand:{$addToSet:{'feedbacks.reportedly':'skillset.userId}}}
© www.soinside.com 2019 - 2024. All rights reserved.