2015-06-05 54 views
3
@Document 
class Entity1 { 
    @Id 
    String id 
    @DbRef(lazy=true) 
    Entity2 entity2; 
    String test; 
} 

mongoTemplate.upsert(
    new Query(Criteria.where("entity2.$id").is(entity2Id), 
    new Update().set("test", "newValue"), 
    Entity1.class); 

Found $id field without a $ref before it, which is invalid如何UPSERT MongoDB的文档使用DBREF春天mongoTemplate

我的问题是:如何做到这一点UPSERT与DBREF。

+0

嗨,大家好,如果你要downvote我的问题,请至少发表评论和告诉我为什么,谢谢 – Jaiwo99

回答

0

通行证实体到查询,而不是ID。创建并ENTITY2保存到数据库,然后用ENTITY2实例,并更改您的代码:其中(“实体2”)为(ENTITY2)