my document object looks like this
{
"_id" : ObjectId("5b62cfac2046e98de373399c"),
"hindi" : {
"confirmed" : false,
"assigned_to" : "[email protected]",
"candidates" : [
{
"candidate_id" : "9262c520-9640-11e8-bfbf-292ac77d55f9",
"value" : "स्क्रॉल कैसे करें ?",
"createdAt" : NumberInt(1533207154),
"createdBy" : "[email protected]",
"warningList" : [],
"comments" : [
"Correction कैसे स्क्रॉल करें",
"added ?"
]
},
{
"candidate_id" : "297bb060-9642-11e8-ac2d-93ac27f5ee90",
"value" : "स्क्रॉल कैसे करें ?",
"createdAt" : NumberInt(1533207154),
"createdBy" : "[email protected]",
"warningList" : [],
"comments" : [
"Correction कैसे स्क्रॉल करें",
"added ?"
]
}
]
}
My objective is to find an particular item inside candidates array by the candidate_id and update the comment field.
Here is the query I'm trying with MongoDB positional operator($) but getting an error Unsupported projection option: $set: { hindi.candidates.$.comments: [] }
db.getCollection("strings").update({_id: ObjectId("5b62cfac2046e98de373399c"),"hindi.candidates.candidate_id": "297bb060-9642-11e8-ac2d-93ac27f5ee90"}, {$set :{"hindi.candidates.$.comments" : []}})
commentsarray or want to$setit as[]?db.getCollection("strings").update( { "_id": ObjectId("5b62cfac2046e98de373399c"), "hindi.candidates": { "$elemMatch": { "candidate_id": "297bb060-9642-11e8-ac2d-93ac27f5ee90" } } }, { "$set": { "hindi.candidates.$.comments" : [] }} )