If you want to use the operator $in the update part, you must explicitly write that arrayin the request part. So,
mongoTemplate.updateFirst(
query(where("name").is("Award1")),
Update.update("brand.$.descr", "Desc2"),
Awards.class);
it should be
mongoTemplate.updateFirst(
query(where("name").is("Award1"))
.and("brand.name").is("Brand1"), // "brand" in "brand.name" is necessary, others according to your requirement
Update.update("brand.$.descr", "Desc2"),
Awards.class);
If you know the position of the element in the array, `$ 'is not necessary, you can try the following:
mongoTemplate.updateFirst(
query(where("name").is("Award1")),
Update.update("brand.0.descr", "Desc2"), // 0 is the index of element in array
Awards.class);
The same way of processing the field name.
source
share