我需要使用 spring-boot 中的 mongo 模板使用另一个字段来更新字段值。我知道如何使用 MongoDB 查询来做到这一点。但是在MongoTemplate不将数据加载到内存的情况下,无法从数据库级别找到一种方法。
我正在寻找这样的东西。它value1在集合中,需要从嵌套数组 ( menu) 中的值更新,并且第 0 个索引始终包含该值。
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);