title: Mongo DB, PHP add or update a field in a document
body: <p>I have the following document:</p>
  
  <pre><code>{
     "_id": ObjectId("5241f1d79b7e7aed05000000"),
     "description": {
       "nl": "Hallo",
       "en": "Hello"
      },
    "name": "Marc"
  }
  </code></pre>
  
  <p>Now I need to update to update one existing field or add new field to the description. In php I use the update function for Mongo and the following code:</p>
  
  <pre><code>$new_data = array(
      '$set' =&gt; array(
      "description" =&gt; array(
           "de" =&gt; "hallo"
         )
      )
  );
  </code></pre>
  
  <p>What it does it removes all other fields and just insert the "de" field. I tried replacing $set with $push (which I thought was made for this) but no result also $setOnInsert does not do anything.</p>
  
  <p>How can I solve this problem so that I can either add a new field (if it does not exist) or update if it exist.</p>
  
  <p>Thanks</p>