title: Targeting a query in Mongo to find and email nested in an object
body: <p>I'm trying to do a query for an endpoint in my Node/Express &amp; Mongo/Mongoose API.</p>
  
  <p>Here is a representation of the document/schema I'm trying to query:</p>
  
  <pre><code>{
    "_id" : ObjectId("59474bc3478604a75e1980e2"),
    "initial" : "D",
    "last_name" : "Spitz",
    "first_name" : "Chris",
    "owner_id" : "59474b92478604a75e1980e1",
    "contacts" : [
      {
        "last_name" : "Jones",
        "first_name" : "Tom",
        "_id" : ObjectId("5947fd928389ffb393fbc310"),
        "addresses" : [ ],
        "phones" : [ ],
        "emails" : [
          {
            "email_type" : "home",
            "email_address" : "runner@running.com",
            "_id" : ObjectId("5947fd928389ffb393fbc311")
          },
          {
            "email_type" : "home",
            "email_address" : "jake@samsonite.com",
            "_id" : ObjectId("5947ff9ed8fa7cb4c781acc9")
          }
        ]
      },
      {
        "last_name" : "Smith",
        "first_name" : "Linda",
        "_id" : ObjectId("5947ff9ed8fa7cb4c781acc8"),
        "addresses" : [ ],
        "phones" : [ ],
        "emails" : [
          {
            "email_type" : "home",
            "email_address" : "chris@chrisnakea.com",
            "_id" : ObjectId("5947ff9ed8fa7cb4c781acc9")
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>I'm trying to check if an email exists in the "contacts.email" array of the document.</p>
  
  <p>Here is the way I'm checking (based on the whey it the item is nested in the schema above):</p>
  
  <pre><code>  Profile.find({'contacts.emails.email_address':req.body.invited_email}, function(err, profile){
      if(err)
        console.log('Error in looking for profile.');
      if(profile.contacts.emails.email_address !== null){
        console.log('Found contact: ' + profile.contacts.emails.email_address);
      } else {
        console.log('Contact does not exist');
      }
    })
  </code></pre>
  
  <p>But for some reason I'm getting a "TypeError: Cannot read property 'emails' of undefined" error in the console when testing.</p>
  
  <p>What am I missing here?</p>