【发布时间】:2018-04-28 20:07:00
【问题描述】:
我有这个问题:
Query query = new Query();
query.addCriteria(where("cakes.color.owner._id").is(new ObjectId(person.getId())));
Update update = new Update();
update.set("cakes.color.owner", person);
mongoOperations.updateMulti(query, update, StockEntity.class);
这是我使用的对象的结构:
public class StockEntity {
private List<Cake> cakes= new ArrayList<>();
}
public class Cake implements Serializable {
private Color color;
}
public class Color implements Serializable {
private Seller owner;
}
问题是我得到了错误:
Write failed with error code 16837 and error message 'cannot use the part (cakes of cakes.color.owner) to traverse the element({cakes:[{cake:{color:{owner:_id:ObjectId('5a0c1bd15efad44437b2e76d')}}}]} )
为什么会出现这个错误?有什么想法吗?
谢谢!
【问题讨论】:
-
因为您正在尝试更新数组中的字段
-
我尝试使用 elemMatch 但我遇到了同样的错误。
标签: spring mongodb updates criteria spring-data-mongodb