title: Updating a embedded array in MongoDB
body: <p>I asked on a <a href="https://stackoverflow.com/questions/19432909/mongodb-embed-structure-updating-and-searching">previous question</a> on how to find entries in a embedded MongoDB document.
  Sitting with a new issue now. My structure looks like :</p>
  
  <pre><code>{
      "_id" : ObjectId("5260c4bd95f8e3ad08000000"),
      "ip" : "127.0.0.1",
      "services" : [ 
          {
              "port" : "22"
          }
      ]}
  </code></pre>
  
  <p>I want to add a new key/value pair to services.port where the port is 22, so that it looks like this :</p>
  
  <pre><code>{
      "_id" : ObjectId("5260c4bd95f8e3ad08000000"),
      "ip" : "127.0.0.1",
      "services" : [ 
          {
              "port" : "22",
              "product" : "ssh"
          }
      ]}
  </code></pre>
  
  <p>This is the update I run :</p>
  
  <pre><code>db.hosts.update({ "ip" : "127.0.0.1" }, { $addToSet : { services : { "port" : "22", "product" : "ssh" }}});
  </code></pre>
  
  <p>And this is what I am getting</p>
  
  <pre><code>{
      "_id" : ObjectId("5260c4bd95f8e3ad08000000"),
      "ip" : "127.0.0.1",
      "services" : [ 
          {
              "port" : "22"
          }, 
          {
              "port" : "22",
              "product" : "ssh"
          }
      ]}
  </code></pre>
  
  <p>Anyone know what I am doing wrong? Should I delete the entry and recreate it?</p>