派生查询不适用于DBRef [英] Derived Queries not working with DBRef

查看:105
本文介绍了派生查询不适用于DBRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Mongo与Spring Data结合使用.

I am using Mongo with Spring Data.

我有两个(第一类)实体(@Documents)Entity1和Entity2,其中Entity1在其中具有Entity2的引用(@DBRef).一切正常,但是执行诸如:

I have two (first class) entities (@Documents) Entity1 and Entity2, where Entity1 has a reference (@DBRef) of Entity2 within it. Everything works fine, but when executing derived queries such as :

public List<Entity1> findByEntity2Property1(String property1)

尽管有带有给定查询参数的文档,但上面的查询没有返回结果.为什么会这样?

The above query returns no results although there are documents with the given query params. Why is that?

推荐答案

我不认为查询可以像您期望的那样工作,因为MongoDB几乎不允许对通过a指向的相关文档的属性进行限制DBRef.因此,您基本上必须查询与属性Property1上给定值匹配的所有Entity2实例,然后针对第一个查询的结果查询与DBRef ed属性匹配的Entity1实例.

I don't think the query can work as you expect it to work as MongoDB pretty much does not allow restricting results on properties of related documents pointed to via a DBRef. So you essentially have to query all Entity2 instances matching the given value on property Property1 and then query for Entity1 instances matching the DBRefed property against the results of the first query.

这篇关于派生查询不适用于DBRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆