Spring data mongo db查询嵌入文档的内部字段(DBRef)

Spring data mongo db查询嵌入文档的内部字段(DBRef),spring,mongodb,mongodb-query,spring-data-mongodb,Spring,Mongodb,Mongodb Query,Spring Data Mongodb,我有一份文件,其中引用了另外两份文件。我必须根据UserLogin和shopmaster的id进行查询。我怎样才能做到这一点。请建议如何查询 @Id private String userShopAssociationId; @DBRef private UserLogin userLogin; @DBRef private ShopMaster shopMaster; Query query = new Query(); query.addCriteria(Criteria.where(

我有一份文件,其中引用了另外两份文件。我必须根据UserLogin和shopmaster的id进行查询。我怎样才能做到这一点。请建议如何查询

@Id
private String userShopAssociationId;

@DBRef
private UserLogin userLogin;

@DBRef
private ShopMaster shopMaster;

Query query = new Query();
query.addCriteria(Criteria.where("userLogin.$id").is(userShopAssociationForm.getUserLoginId()));
query.addCriteria(Criteria.where("shopMaster.$id").is(userShopAssociationForm.getShopMasterId());

你的疑问看起来是正确的;您应该能够基于DBRef的
\u id
进行查询。这是因为DBRef将集合、id和(有时)数据库存储在父文档上。但是,您可能需要将正在比较的ID转换为
ObjectId
,如下所示:

Query query = new Query();
query.addCriteria(Criteria.where("userLogin.$id").is(new ObjectId(userShopAssociationForm.getUserLoginId())));
query.addCriteria(Criteria.where("shopMaster.$id").is(new ObjectId(userShopAssociationForm.getShopMasterId()));

如果不是dbref呢?