Using: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE
I have a document class defined like this:
@Document
public class MyDoc
{
@Indexed
@DBRef
private User owner;
...
I'm trying to select all MyDoc instances for a particular user with this repository definition:
public interface MyDocRepository extends CrudRepository<MyDoc, String>
{
List<MyDoc> findByOwner(User owner);
}
Unfortunately this doesn't find anything: the code runs fine, no exception, but alas nothing is found.
So what is the proper way to select documents by a DBRef-ed field?
NB. I have seen this question but my use case is simpler as I don't want to filter by a property of the DBRef-ed entity.
Update: Until repositories support finding by DBRef, I've decided to go with a simple workaround: use the MongoTemplate to form a query that uses a com.mongodb.DBRef as a field criteria. Works fine.