Derived queries not working with DBRef

I am using Mongo with Spring data.

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

public List<Entity1> findByEntity2Property1(String property1) 

The above query does not return results, although there are documents with the specified query parameters. Why is this?

+2
source share
1 answer

I don’t think that a query can work the way you expect it to work, since MongoDB does not allow you to limit the results significantly on the properties of related documents that are referenced through DBRef . Therefore, you need to query all Entity2 instances matching the given value of Property1 , and then query Entity1 instances matching DBRef ed compared to the results of the first query.

0
source

Source: https://habr.com/ru/post/1395715/


All Articles