I have a document of this kind.
{
"id": "5a212b985735dd44089e4782",
"people": [
{
"personId": "5a212b985735dd44089e4783",
"name": "Ronaldo",
"parents": [
{
"parentId": "5a212b985735dd44089e4784",
"name": "Messi",
"address": [
{
"addressId": "5a212b985735dd44089e4785",
"country": "Argentina",
"city": "Blah Blah"
},
{
"addressId": "5a212b985735dd44089e4786",
"country": "USA",
"city": "New York"
}
]
}
]
}
]
}
I have to replace the exiting parent object inside the parents array with a new parent object.
The code I have written is:
Query query = new Query(Criteria.where("id").is("5a212b985735dd44089e4782"));
Update update = new Update().push("people.$.parents", parent);
this.mongoTemplate.findAndModify(query, update, PeopleInfo.class);
However, instead of replacing the existing parent object, it is creating a new one.
Does anyone know how to perform a query of this kind?