title: Upsert Array Elements matching criteria in a MongoDB document?
body: <p>As per <a href="https://stackoverflow.com/questions/7967184/how-do-i-update-array-elements-matching-criteria-in-a-mongodb-document">How do I update Array Elements matching criteria in a MongoDB document?</a></p>
  
  <p>I want to upsert the array elements, so if one doesnt match then insert it, otherwise update it.</p>
  
  <p>I tried the answer on that question, and it works fine IF the array element already exists. If the element doesnt exist then it creates a child of "$" under the array field.</p>
  
  <p>My Mongo structure is as follows:</p>
  
  <pre><code>Widget (collection)
  --Name
  --Properties (array)
    --Name
    --Value
  </code></pre>
  
  <p>My application gets a Widget Name and a list of Properties from a WebService call. I wish to iterate the provided Properties and update the value in the MongoDB if the Name already exists, OR insert a new Property to the Properties array if it doesnt.</p>