title: Is there a way to merge a hash field on a document with a new hash on upsert in MongoDB?
body: <p>Suppose I have a MongoDB document with a field <code>values</code> which contains a hash <code>{a: 1, b: 2, c: 3}</code>. I then go on to upsert a new version of this document where <code>values: {c: 4, d: 5}</code>.</p>
  
  <p>What I am trying to find is a way to have Mongo merge the hashes Mongo-side without me having to pull down the previous version of the document first. I.e. the resulting document after the upsert should have <code>values: {a: 1, b: 2, c: 4, d: 5}</code>.</p>
  
  <p>It is currently possible to do this in RethinkDB by providing a custom conflict-resolution lambda function that handles the merging of the old_doc + new_doc. ( <a href="https://www.rethinkdb.com/api/ruby/insert/" rel="nofollow noreferrer">https://www.rethinkdb.com/api/ruby/insert/</a> )</p>
  
  <p>Is it possible to replicate this in Mongo?</p>