title: Spring MongoDB + QueryDSL query by @DBRef related object
body: <p>I am using spring-data-mongodb and querydsl-mongodb to perform more flexible queries.</p>
  
  <p>My application has users and orders.
  An user can have multiple orders, so my models looks like this:</p>
  
  <pre><code>public class User {
  
    @Id
    private String id;
    private String username;
  
   //getters and setters
  }
  
  public class Order {
    @Id
    private String id;
  
    @DBRef
    private User user;
  
    //getters and setters
  }
  </code></pre>
  
  <p>As you can see, there is an has-many relationship between users and orders.
  Each order is assigned to an user, and the user is stored in @DBRef public User user attribute.</p>
  
  <p>Now, lets say that an user has 10,000 orders.</p>
  
  <p>How can i make the query to get all orders that belongs to an specific user ?</p>
  
  <p>I have the OrderRepository:</p>
  
  <pre><code>public interface OrderRepository extends MongoRepository&lt;Order, String&gt;,
          QueryDslPredicateExecutor&lt;Order&gt; {
  
  }
  </code></pre>
  
  <p>I tried this solution but it doesnt return anything:</p>
  
  <pre><code>QOrder order = new QOrder("order");
  Pageable pageable = new PageRequest(0, 100);
  
  return userRepository.findAll(order.user.id.eq(anUserId), pageable);
  </code></pre>
  
  <p>I need to use querydsl because i want to build a service that can query orders by more many prameters than userid. For example i want to get all orders that belongs to user with specific username.</p>