Spring Data mongoTemplate.save() behaviour
<p>When you persisting a document using mongoTemplate.save() it destroys all unmapped fields in the database document. </p>

<p>For example, you have a collection "myDocument" with the document in the mongodb:</p>

<pre><code>{
  "_id": ObjectId("552402c3186eb112488b45ea"),
  "field1": "value1",
  "field2": "value2"
}
</code></pre>

<p>and your domain object looks like:</p>

<pre><code>public class MyDocument {
  @Id
  private String id;
  private String field1;

  // getter and setter
}
</code></pre>

<p>after <strong>updating</strong> your document:</p>

<pre><code>MyDocument doc = myDocumentRepository.getById(&lt;some_id&gt;);
doc.setField1("value3");
mongoTemplate.save(doc);
</code></pre>

<p>you will get the document in the collection without "field2":</p>

<pre><code>{
  "_id": ObjectId("552402c3186eb112488b45ea"),
  "field1": "value3"
}
</code></pre>

<p>It looks like unexpected behaviour and may be a real stopper when few different applications are using the same database.</p>

<p>Is overriding of MongoTemplate method is acceptable workaround? 
Any other ideas will be very appreciated.</p>

<p>Thanks.</p>

<p><strong>update</strong></p>

<p>As noted by @helmy this is how mongoTemplate.save() works and usage of update methods is preferred. But in this case I'm loosing lifecycle events that built into mongodb mapping framework. For example, validation will not works on update as it triggered by listener in onBeforeSave event...   </p>