ObjRelationPojo表一條記錄
public class YpObjRelationPojo implements Serializable { @Id private String id; // '主鍵id' @Field("sourceid") private String sourceId; //對象id @Field("targetid") private String targetId; //對象id @Field("caseId") private String caseId; //案件id @Transient //配置透明屬性 private int source; // '關系起點 不存數據庫 @Transient private int target; // '關系終點 不存數據庫 @Transient private String color; @Transient private String relation; // '關系名稱' @Field("relation_type") @DBRef private YpRelationTypePojo relation_type; @Field("create_time") private Date create_Time; // '創建時間'
省略了set,get方法
@DBRef用於關聯對象
{
"_id" : ObjectId("54a24e8a25600d768a4e13ac"),
"sourceid" : "54a20a6dd9d886078991aa98",
"targetid" : "54a209dfd9d886078991aa95",
"caseId" : "100",
"relation_type" : {
"$ref" : "relationtype",
"$id" : ObjectId("54a21b0ad9d886078991aa9e")
}
}
如果需要查找出這條記錄中的relation_type,查看相關聯的對象
我們需要使用點表示法則
Id為relation_type表的記錄id
ObjectId objectId = new ObjectId(Id);
Query query1=Query.query(Criteria.where("relation_type.$id").is(objectId));
List<YpObjRelationPojo> r=mongoTemplate.find(query1, YpObjRelationPojo.class, "YpObjRelationPojo");
找出之后,刪除該字段
Update update=new Update();
update.unset("relation_type");