title: Mongoose find/update subdocument
body: <p>I have the following schemas for the document <strong>Folder</strong>:</p>
  
  <pre><code>var permissionSchema = new Schema({
      role: { type: String },
      create_folders: { type: Boolean },
      create_contents: { type: Boolean }
  });
  
  var folderSchema = new Schema({
      name: { type: string },
      permissions: [ permissionSchema ]
  });
  </code></pre>
  
  <p>So, for each Page I can have many permissions. In my CMS there's a panel where I list all the folders and their permissions. The admin can edit a single permission and save it.</p>
  
  <p>I could easily save the whole <strong>Folder</strong> document with its permissions array, where only one permission was modified. But I don't want to save all the document (the real schema has much more fields) so I did this:</p>
  
  <pre><code>savePermission: function (folderId, permission, callback) {
      Folder.findOne({ _id: folderId }, function (err, data) {
          var perm = _.findWhere(data.permissions, { _id: permission._id });                
  
          _.extend(perm, permission);
  
          data.markModified("permissions");
          data.save(callback);
      });
  }
  </code></pre>
  
  <p>but the problem is that <strong>perm</strong> is always <strong>undefined</strong>! I tried to "statically" fetch the permission in this way:</p>
  
  <pre><code>var perm = data.permissions[0];
  </code></pre>
  
  <p>and it works great, so the problem is that Underscore library is not able to query the permissions array. So I guess that there's a better (and workgin) way to get the subdocument of a fetched document.</p>
  
  <p>Any idea?</p>
  
  <p><em>P.S.: I solved checking each item in the data.permission array using a "for" loop and checking data.permissions[i]._id == permission._id but I'd like a smarter solution, I know there's one!</em></p>