簡體   English   中英

如何使用spring mongoTemplate使用DbRef升級MongoDB文檔

[英]How to upsert MongoDB Document with DbRef using spring mongoTemplate

@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

我的問題是:如何用DbRef做這個upsert。

將實體傳遞給查詢,而不是id。 創建Entity2到DB,然后使用entity2實例並將代碼更改為:where(“entity2”)。is(entity2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM