title: MongoDB how do I use $set and $aggregate to set field of nested documents?
body: <p>I want to write an expression that allows me to set the field <code>checked</code> of my items nested within an other document. How can I achieve this in MongoDB?</p>
  
  <pre><code>{ "_id" : ObjectId("55081de2162072120758fc53")[ 
   {
    "_id": "55081de2162072120758fc53",
    "items": [
     {
      "checked": false,
      "name": "Apples",
      "_id": "554df987a8e9950134aa72bd"
     },
     {
      "checked": false,
      "name": "Jam",
      "_id": "554df98ba8e9950134aa72be"
     }
    }
   ]
   ...
   }
  </code></pre>
  
  <p>In order to access a single item I do the following:</p>
  
  <pre><code>xy.aggregate([
    {$match: {_id: new ObjectId(idlist)}},
    {$unwind: '$items'},
    {$match: {'items._id': new ObjectId(iditem)}},
    {$project: {_id: false, item: '$items'}}
  </code></pre>
  
  <ul>
  <li><strong>How can I write a query that allows me to set the <code>Apples</code> item to <code>false</code>?</strong></li>
  <li><strong>And is there an easier way to write the aggregation query above?</strong></li>
  </ul>