I am going to update some fields of mongoose document according to provided keys. For example, When we present mongoose document in json.
user: {
  address: {
    city: "city"
    country: "country"
  }
}
And update params is given like this.
address: {
   city: "city_new"
}
when I run the mongoose api like this.
let params = {
   address: {
      city: "city_new"
   }
}
User.set(param)
It replace whole address object and final result is
user: {
  address: {
    city: "city_new"
  }
}
it just replace address field, but I want to only update city field. This is desired result.
user: {
  address: {
    city: "city_new"
    country: "country"
  }
}
How to do this in mongoose?
When nested object has more complex hierarchy, how can we solve this without manually indicate field like address.city.field1.field2. ...
Thanks
 
     
     
    