title: 'upsert' in an embedded document
body: <p>I currently have the following dataset:</p>
  
  <pre><code>{  
      'component_id':1,  
      '_locales':[   
          {  
              'url': 'dutch',  
              'locale': 'nl_NL'  
          } 
      ] (etc)
  }
  </code></pre>
  
  <p>If I want to update the row with the locale I would run something similar to:</p>
  
  <pre><code>db.components.update(
      {'component_id': 1, '_locales.locale': 'nl_NL'},
      {$set: {'_locales.$': {'url': 'new url','locale':'nl_NL'}}, 
      true
  );
  </code></pre>
  
  <p>This works fine untill the locale does not exists:</p>
  
  <pre><code>db.components.update(
      {'component_id': 1, '_locales.locale': 'en_US'},
      {$set: {'_locales.$': {'url': 'new url','locale':'en_US'}}, 
      true
  );
  </code></pre>
  
  <p>since there is a unique index on component_id this will throw an exception complaining about a duplicate key.</p>
  
  <p>Is there a way to automatically add the new 'document' with a different locale and update it if it already exists? According to the documentation using the position operator will not work with 'upserting'.</p>