title: MongoDB: insert on duplicate key update
body: <p>How can do this with Mongo in one [atomic] statement:</p>
  
  <pre><code>insert mytable set MyUniqueKey = ?, X = ? on duplicate key update Y = ?
  </code></pre>
  
  <p>When this statement is executed for first time it will set X value but after that it will only update Y value.</p>
  
  <p>Only MyUniqueKey is part of unique key and should be looked up for duplicates.</p>