【问题标题】:Derived Queries not working with DBRef派生查询不适用于 DBRef
【发布时间】:2011-12-29 14:46:33
【问题描述】:

我正在使用带有 Spring Data 的 Mongo。

我有两个(第一类)实体 (@Documents) Entity1 和 Entity2,其中 Entity1 在其中包含 Entity2 的引用 (@DBRef)。一切正常,但是在执行派生查询时,例如:

public List<Entity1> findByEntity2Property1(String property1)

尽管存在具有给定查询参数的文档,但上述查询未返回任何结果。这是为什么呢?

【问题讨论】:

  • 您好,您能找到任何解决方案吗?谢谢。

标签: java spring mongodb spring-data spring-data-document


【解决方案1】:

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

【讨论】:

  • 谢谢!这是唯一(也是推荐的)出路吗?还是有(可能更好的)替代品?
  • 另外,then query for Entity1 instances matching the DBRefed property against the results of the first query - 你是怎么做到的?
  • @Saket 你找到解决办法了吗?
猜你喜欢
  • 2020-04-08
  • 2021-04-20
  • 2012-01-04
  • 2012-11-01
  • 1970-01-01
  • 2012-03-02
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多