'trying to update nested array in mongodb
` "id": 1,
"name": "Afghanistan",
"iso3": "AFG",
"iso2": "AF",
"states": [
{
"id": 3901,
"name": "Badakhshan",
"state_code": "BDS",
"latitude": "36.73477250",
"longitude": "70.81199530",
"type": null,
"cities": [
{
"id": 52,
"name": "Ashkāsham",
"latitude": "36.68333000",
"longitude": "71.53333000"
},
dbo.collection("countries").updateOne(myquery,
{ $set: { "states.$[].cities.$[filter].name": new_name } },
{ arrayFilters: [ {"filter.name":old_city_name} ] },
async function (err, result) {
if (err) {
return res.json({ success: false, response: err.message, statusbar: err })
}
res.json({ success: true, statuscode: 200, response: result });
db.close();
});
trying to update a city name which in the states array its working but its updating every city in that particular state need some help guys
tq all
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
