title: spring data - Mongodb - findBy Method for nested objects
body: <p>I have two domain objects,</p>
  
  <pre><code>@Document
  public class PracticeQuestion {
  
       private int userId;
       private List&lt;Question&gt; questions;
  
  // Getters and setters
  }
  
  @Document
  public class Question {
  
       private int questionID;
       private String type;
  
  // Getters and setters
  }
  </code></pre>
  
  <p>My JSON doc is like this,</p>
  
  <pre><code>{
      "_id" : ObjectId("506d9c0ce4b005cb478c2e97"),
      "userId" : 1,
      "questions" : [
          {
              "questionID" : 1,
              "type" : "optional"
  
           },
          {
               "questionID" : 3,
               "type" : "mandatory"
          }
      ]
  }
  </code></pre>
  
  <p>I have to update the "type" based on userId and questionId, so I have written a findBy query method inside the custom Repository interface,</p>
  
  <pre><code>public interface CustomRepository extends MongoRepository&lt;PracticeQuestion, String&gt; {
  
      List&lt;PracticeQuestion&gt; findByUserIdAndQuestionsQuestionID(int userId,int questionID);       
  }
  </code></pre>
  
  <p>My problem is when I execute this method with userId as 1 and questionID as 3, it returns the entire questions list irrespective of the questionID.  Is the query method name valid or how should I write the query for nested objects.</p>
  
  <p>Thanks for any suggestion.</p>