I need to update nested array in mongodb using nodejs. I have tried like this but not helped and even its not throwing error.
My Collection is this
{
"country_details": [
{
"cities": [
"Abbeville"
],
"_id": "5a6ec189bb68bb09105eabe8",
"countryCode": "US",
"countryName": "United States"
}
],
"deletion_indicator": "N",
"_id": "5a6ec189bb68bb09105eabe7",
"date_created": "Mon Jan 29 2018 12:09:05 GMT+0530 (India Standard Time)",
"__v": 0
}
and I want to update cities, And I have try like one
let query = {_id: "5a6ec189bb68bb09105eabe7", countryCode: "US", countryName: "United States"};
countryAndCitiesModel.collection.update(
query,
{$push: {"country_details.$.cities": "ABC"}},
(err, result)=> {
if(err){
return next(err);
}else{
return next(result);
}
});
not getting update, but getting result like is
{
"ok": 1,
"nModified": 0,
"n": 0
}
Please help.. Thanks
