'Update nested array object field in mongodb using spring boot
New to mongodb, Tring to update multiple array object field of an document. not getting expected result
Document Structure:
{
"_id" : ObjectId("4faaba123412d654fe83hg876"),
"user_id" : 123456,
"items" : [{
Name:{
"id":1,
"item_name" : "my_item_one",
"price" : 20
},
Details:{
"Date" : "10/02/2022",
"Address":"test"
}}],
[{
Name:{
"id":2,
"item_name" : "my_item_two",
"price" : 20
},
Details:{
"Date" : "10/02/2022",
"Address":"test"
}}]
}
Based on id need to update date
Spring boot code
Query query = new Query(Criteria.where("user_id").is("123456").and("items")
.eleMatch(Criteria.where("items.Name.id").is(1)));
Update update = new Update().set("items.0.Details.Date", "29/01/2022");
mongoOperation.findAndModify(query, update, Items.class);
but when I run this query it is returning null Can any one help on this Thanks , Also tried
Query query = new Query(Criteria.where("user_id").is("123456").and("items")
.eleMatch(Criteria.where("items.Name.id").is(1)));
Update update = new Update().set("items.Details.Date", "29/01/2022");
mongoOperation.findAndModify(query, update, Items.class);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
