I import to mongodb a database, that looks like this:
{
other values,
"addresses" : [
{
"_id" :
"createdAt" :
"likes" :
"type" :
"route" :
"country" :
"administrative_area_level_1" :
"administrative_area_level_2" :
"locality" :
"postal_code" :
"street_number" :
}
],
other values
}
I want to add a new property to the database and thus create this schema:
const schema = new Schema({
addresses: [{
route: String,
coordinates:[{
coordsSet: {
type: Boolean,
default: false
},
lat: String,
lon: String
}]
}],
name: String,
});
And while I can find the record by ID for example I am unable to set coordinates to the new record after I call google API. I do it this way:
baza.findOneAndUpdate({ "addresses._id": response.id }, {$set: {"addresses.coordinates[0].lat": response.lat}}).then((update) =>{
res.send(update);
})
But I am unable to do that. res.send shows that I created "coordinates": []
, however I cannot set it.
I dont have this problem when I want to add those new properties outside the adresses object, so I suppose I am failing with nesting some information. What am I doing wrong?