title: Update field inside document by id in MongoDB
body: <p>I want to add (+1) a qty field inside a collection with documents like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>    {"_id": { "$oid" : "531cc2410b4ebf000036b2d7" },
     "name": "ALMACEN 2",
     "items": [
          {
            "id": "111111",
            "marca": "BJFE",
            "tipo": 0,
            "color": "GDRNCCD",
            "mano": 1,
            "modelo": 0,
            "qty": 1
          },
          {
            "marca": "BJddFE",
            "tipo": 0,
            "color": "GDffRNCCD",
            "mano": 1,
            "modelo": 0,
            "qty": 3
          },
          {
            "marca": "BJeeFE",
            "tipo": 0,
            "color": "GDRNCCD",
            "mano": 1,
            "modelo": 0,
            "qty": 9
          }   ] }
  </code></pre>
  
  <p>I want to add +1 to qty in the document with _id = 531cc2410b4ebf000036b2d7 and inside items, with id=1111.</p>
  
  <p>Is it possible?</p>
  
  <p>EDIT:</p>
  
  <p>with this code</p>
  
  <pre class="lang-js prettyprint-override"><code>warehouses.update(
      {_id: new ObjectID(warehouseId)},
      {"$inc": { "items.$.qty": -1 }},
       function (e, docs) {
          if (e) {
              error(e);
              return;
          }
  
          success(docs);
      });
  </code></pre>
  
  <p>I have error:</p>
  
  <blockquote>
    <p>cannot apply the position operator without a corresponding query field containing an array</p>
  </blockquote>
  
  <p>Finally this works:</p>
  
  <pre><code> warehouses.update({_id: new ObjectID(warehouseId), "items.id": itemId}, {"$inc": { "items.$.qty": -1 }}, function (e) {
          if (e) {
              error(e);
              return;
          }
  
          success();
      });
  </code></pre>