title: How to retrieve parent document based on subdocument values in Mongoose?
body: <p>I have the following schema's:</p>
  
  <pre><code>var Child = new mongoose.Schema({
      'field': String,
      'value': String
    });
  
  var Parent = new mongoose.Schema({
      'name': String,
      'children': [ Child ]
    });
  </code></pre>
  
  <p>I want to return the <code>Parent</code> for which one of the <code>Child</code>'s corresponds to the following JSON object:</p>
  
  <pre><code>{ 'field': 'Family Name', 'value': 'Smith' }
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>Parent.findOne({ 'children': { 'field': 'Family Name', 'value': 'Smith' } }, fn ...)
  </code></pre>
  
  <p>but it keeps on retrieving <code>null</code>.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Testing through the Mongo shell extension, I found out that the <code>Child</code> sub-documents have their own <code>_id</code>'s. If I add that <code>_id</code> to the query, it fetches the <code>parent</code> document. Now, I don't know in advance what that child <code>id</code> will be. So: how can I remove it from the sub-document query? (In other words, the above query literally looks for a JSON object with only two properties, while the sub-documents have three)</p>
  
  <p>My environment is: Node.js, Mongoose, MongoDB</p>