This is the json object
{
"account_id":"1",
"sections":[ {
"section_name":"abc",
"labels": [{
"name": "label1",
"value": "value1"
},
{
"name": "label2",
"value": "value2"
}]
},
{
"section_name":"def",
"labels": [{
"name": "label3",
"value": "value3"
}]
}]
}
In this json object I wanted to change the value of label3 from value3 to value4 in the section def. There are different accounts but I have listed only one json object here.
I have used the below code, but it didn't work for me. Here I have passed section name(section), label name (label) and label value (value).
let query = {
account_id: event.accountId.toString(),
sections: {
section_name: section,
labels: {
label_name: label
}
}
};
return using(connectDatabase(), db => {
return db.collection(TABLE_NAME).updateOne(query, { $set: {
'sections.$.labels.$.value': value } });
}).then(
result => {
cb(null, responseObj(result, 200));
},
err => {
cb(responseObj(err, 500));
}
);
Can someone help me ? Thanks in advance