title: Spring Data query over two documents
body: <p>I have an m:n connection in my MongoDB, <strong>MessageUserConnection</strong> is the class between User and Message.
  Now I will get all MessageUserConnections where <strong>MessageUserConnection#confirmationNeeded</strong> is true, read is false and <strong>Message#receiveDate</strong> is not older than the last week. 
  Is there any possibility to do this with Spring Data?
  Thanks a lot!  </p>
  
  <pre><code>public class MessageUserConnection {
  
      @Id
      private String id;
      @DBRef
      private User userCreatedMessage;
      @DBRef
      private Message message;
      private Boolean confirmationNeeded;
      private Boolean read;
  }
  
  public class Message {
  
      @Id
      private String id;
      private String title;
      private String message;
      private DateTime receiveDate;
  }
  </code></pre>
  
  <p><strong>[EDIT]</strong>
  I have tried it by my own: </p>
  
  <pre><code>@Query("FROM MessageUserConnection AS muc WHERE muc.confirmationNeeded = ?0 AND muc.message.receiveDate = ?1")  
  List&lt;MessageUserConnection&gt; findMessageUserConnectionByConfirmationNeededAndReceiveDate(final Boolean confirmationNeeded, final DateTime receiveDate);
  </code></pre>
  
  <p>and I get the following exception: </p>
  
  <blockquote>
    <p>Caused by: com.mongodb.util.JSONParseException: 
    FROM MessageUserConnection AS muc WHERE muc.confirmationNeeded = "_param_0" AND muc.message.receiveDate = "_param_1"</p>
  </blockquote>
  
  <p>Does anyone know what I am doing wrong here?
  Thanks a lot!</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>I run into another problem. My query currently looks like this. </p>
  
  <pre><code> @Query("{$and : [{'confirmationNeeded' : ?0}, {'message.receiveDate' : ?1}]}")
  </code></pre>
  
  <p>where confirmationNeeded is a boolean and message.receiveDate is Joda#DateTime. With this query I get the following exception:</p>
  
  <blockquote>
    <p>org.springframework.data.mapping.model.MappingException: Invalid path reference message.receiveDate! Associations can only be pointed to directly or via their id property!</p>
  </blockquote>
  
  <p>Does that mean that I only can join to message.id?
  Thanks a lot!</p>