Usage: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE
I have a document class defined as follows:
@Document public class MyDoc { @Indexed @DBRef private User owner; ...
I am trying to select all MyDoc instances for a specific user using the definition of this repository:
public interface MyDocRepository extends CrudRepository<MyDoc, String> { List<MyDoc> findByOwner(User owner); }
Unfortunately, this does not find anything: the code works fine, without exception, but, alas, nothing was found.
So what is the right way to select documents in the DBRef-ed field?
NB . I saw this question , but my usage example is simpler because I don't want to filter by the property of the DBRef-ed object.
Refresh . While the repositories do not support DBRef search, I decided to go with a simple workaround: use MongoTemplate to generate a query that uses com.mongodb.DBRef as a field criterion. It works great.
source share