Below is my nested array and I want to update a value in inner array. The scenario is similar to this solution
But, I have only inner array inside first array. So , I am not sure how to specify the identifier for the first array
{
"RequestID": "A22A8D43FE5D8D1409D5984003AB5609",
"OPC_REQUEST_ID": [{
"B69BF2DCEBB932A2665920BE14BA14C5": [{
"Message": "Some message ",
"Time": "2020-02-25T07:30:52Z",
"bug": [
"27571088",
"7452257"
],
"label": [
"No Label"
],
"score": -0.5106
}]
},
{
"8E0FCBBF92D7226ADB6F3DB465DDA7F4": [{
"Message": "Some message",
"Time": "2020-02-25T07:31:52Z",
"bug": [],
"label": [
"No Label"
],
"score": -0.7184
}]
}
]
}
I tried below query, but the key for the identifier "j" is another array , so I am not sure how specify key/value for "j" in the "arrayFilters"
db.requestid.update({'RequestID':'A22A8D43FE5D8D1409D5984003AB5609'},{'$set':{'OPC_REQUEST_ID.$[j].8E0FCBBF92D7226ADB6F3DB465DDA7F4.$[k].score' : '0'}},
{arrayFilters:[{'j.OPC_REQUEST_ID' :'8E0FCBBF92D7226ADB6F3DB465DDA7F4' }, {'k.Message' : 'Some message'}]})
}
I want to edit the "score" in the second array from -0.7184 to 0 . So the output would become
{
"RequestID": "A22A8D43FE5D8D1409D5984003AB5609",
"OPC_REQUEST_ID": [{
"B69BF2DCEBB932A2665920BE14BA14C5": [{
"Message": "Some message ",
"Time": "2020-02-25T07:30:52Z",
"bug": [
"27571088",
"7452257"
],
"label": [
"No Label"
],
"score": -0.5106
}]
},
{
"8E0FCBBF92D7226ADB6F3DB465DDA7F4": [{
"Message": "Some message",
"Time": "2020-02-25T07:31:52Z",
"bug": [],
"label": [
"No Label"
],
"score": 0
}]
}
]
}