title: How to update and add to subdocument list with Spring+Mongo
body: <p>I have a document like this in a MongoDB collection:</p>
  
  <pre><code>{
    id : ... 
    listA:[{
            id: ...,
            thing:...,
            listB:[{...},{...}]
            },...
              ]
  }
  </code></pre>
  
  <p>(The top level ID is the normal auto-generated MongoDB ID. The other ID of the subdocument object is a pseudo-ID that I've generated separately and pushed into the list)</p>
  
  <p><strong>Questions:</strong> I would like to (1) add to <code>listB</code> and (2) change <code>thing</code></p>
  
  <p>This object can be pretty hefty and it is possible that more than one thread might be operating on the object so I want to avoid a <code>findOne</code>, update, then <code>save</code> type of scenario.</p>
  
  <p>I'd like to do this in Spring Data in a similar way that I've done a push to <code>listA</code>, i.e. </p>
  
  <pre><code>@Autowired
  private MongoOperations operations;
  
  public void addStuff(String id, Stuff stuff) {
      operations.updateFirst(Query.query(Criteria.where("_id").is(id)),
              new Update().addToSet("listA", stuff), Stuffs.class);
  }
  </code></pre>
  
  <p>However I'm having trouble generating the right Query/Criteria.</p>
  
  <p>Thanks in advance.</p>