MongoDB with Spring Data find object in array by id
<p>I am using Spring Data with a Mongo DB embedded database and have the following document structure:</p>

<pre><code>{
  id : 111
  messaage : abcd
  commentsList: [
                  {
                    id : 123
                    text: test text
                    numberOfLikes : 5
                    numberOfDislikes: 2
                  }
                ]     
}
</code></pre>

<p>I am trying to get a comment by id and update the numberOfLikes field by one and can't seem to get it to work, here is what I've tried and the java class structure:</p>

<pre><code>public class Post {

    private String id;
    private String message;
    private List&lt;Comment&gt; commentsList = new ArrayList&lt;&gt;();
    ...
}

public class Comment {

    private String id;
    private String text;
    private int numberOfLikes;
    private int numberOfDislikes;

    ...
}

Query query = new Query();
query.addCriteria(Criteria.where("commentsList._id").is("123"));
List&lt;MongoComment&gt; commentList = mongoTemplate.find(query, MongoComment.class);
</code></pre>

<p>Currently the returned list is always null.</p>