title: MongoDB concurrent update (with sub collection)
body: <p>I started using MongoDB (With spring-data-mongo) at work and so fare all good.
  But I was wondering how does MongoDB deals with occurrent update? And more specifically what are the best practices to handle these ?</p>
  
  <p>For example I have a Document that contains a Map</p>
  
  <pre><code>@Document(collection = "test)
  public class Test {
     private String name;
     private Map&lt;Long, Holder&gt; myMap;
  }
  
  public class Holder {
     private List&lt;Integer&gt; list;
  }
  
  
  { 
    "name": "test",
    "myMap: "{"1":"{"list":[1,2,3]}", "2":"{"list":[1,2,3]}"}"
  }
  
  Thread A: retrieves the Test Document
  Thread A: gets myMap and add a new entry in the list for key "1"
  Thread B: retrieves the Test Document
  Thread B: gets myMap and add a new entry in the list for key "1"
  Thread B: saves the Test Document
  Thread A: saves the Test Document
  </code></pre>
  
  <p>The question is what will be in the myMap ? the entry added by B or A ? or both ?</p>