1
let countryId = 6263135fd3456f312f76e8cb
let cityKey = 'country.'+(0);

await CountryModel.findOneAndUpdate(
{ _id: countryId}, 
{ $push: {cityKey:[]}},
{new:true});

To understand , country Id is the key of this multidimensional array. the array looks like this in mongo db.

_id = Object('6263135fd3456f312f76e8cb')
country:Array
    0:Array

just wondering why i cant use the city key to make the push look like this

{'country.0':[]}

i mean its working when i typed the string like that, but as you would imagine it will be constantly just add to country.0 path. what i want is ive be able to use a variable and make the key/path ('country.Number') like that.

i try appending the 0 'country'+0 like this but it gives me error

thanks hope you can help me

0 Answers0