title: MongoDB $addToSet replace
body: <p>I have a document like the following one:<br></p>
  
  <pre><code>{
      _id: "00112233",
      array: [
          {
              _id: "potatoes",
              amount: 5
          },
          {
              _id: "carrots",
              amount: 6
          }
      ]
  }
  </code></pre>
  
  <p>and I need to update or push the documents so that if there is one in the array, it gets replaced, if not, it gets pushed.<br>
  If i try to do an update like this:</p>
  
  <pre><code>db.collection.update(
      { _id: "00112233" },
      {
          "$push": { "array": { "$each": [
              {
                  _id: "potatoes",
                  amount: 6
              },
              {
                  _id: "apples",
                  amount: 2
              }
          ]}}
      }
  )
  </code></pre>
  
  <p>In the database I will find two "potatoes" field. But if I try to replace the "push" with a "addToSet" I won't have the "potatoes" field updated.<br>
  Is there any way I can do this in only one query?</p>