title: Mongodb embed structure updating and searching?
body: <p>Playing with MongoDB to store results from a nmap network scan, and trying to figure out the best way to structure the data.</p>
  
  <p>At the moment I have the following :</p>
  
  <pre><code>{
      "_id" : ObjectId("525f94097025166583e18eba"),
      "ip" : "127.0.0.1",
      "services" : [ 
          {
              "port" : "22",
              "port_info" : [ 
                  {
                      "product" : "ssh",
                      "version" : "1.0"
                  }
              ]
          }, 
          {
              "port" : "80",
              "port_info" : [ 
                  {
                      "product" : "apache",
                      "version" : "2.0"
                  }
              ]
          }
      ]
  }
  </code></pre>
  
  <p>I can find for example hosts with port 22 open, example against just 127.0.0.1 with this</p>
  
  <pre><code>db.hosts.find({ ip : "127.0.0.1"}, {"services" : { $elemMatch : { port : "22" }}})
  </code></pre>
  
  <p>But I am not sure, how to find for example all hosts, which has "product" : "ssh"
  try does, but I get a syntax error</p>
  
  <pre><code>db.hosts.find({ ip : "127.0.0.1"}, { services.port_info : { $elemMatch : { product : "ssh"    }}})
  </code></pre>
  
  <p>Then let's say I want to add another element to "port_info" maybe something like
      protocol : tcp</p>
  
  <p>how would I do a update, where I say something like update where ip : 127.0.0.1 and product is ssh?</p>