I need a field value to be updated using another field using the mongo template in spring-boot. I am aware of how this can be done using MongoDB queries. But could not figure out a way of doing this using MongoTemplate
from the database level without loading the data to the memory.
I am searching for something like this. The value1
is in the collection and it needs to be updated from a value from a nested array (menu
) and 0th index contains the value always.
Query query = new Query();
query.addCriteria(Criteria.where("price").is(0));
Update update = new Update();
update.set("price", "$menu[0].sellingPrice");
mongoTemplate.updateMulti(query, update, CollectionName);