title: MongoDB Java find nested object using regex
body: <p>I'm using the MongoDB driver to create the query below. I'm just wondering what's the difference between the functionality of the two codes:</p>
  
  <p>Returns 0; <strong>address:{"houseBldgNum"}</strong></p>
  
  <pre><code>db.students.count({ "studentName" : { "$regex" : "(.+)?JAN(.+)?" , "$options" : "i"} , "address" : {"houseBldgNum" : { "$regex" : "(.+)3(.+)?" , "$options" : "i"} }})
  </code></pre>
  
  <p>Returns 2; <strong>address.houseBldgNum</strong></p>
  
  <pre><code>db.students.count({ "studentName" : { "$regex" : "(.+)?JAN(.+)?" , "$options" : "i"} , "address.houseBldgNum" : { "$regex" : "(.+)3(.+)?" , "$options" : "i"} })
  </code></pre>
  
  <p>Data:</p>
  
  <pre><code>{
    "studentName":"JAN M",
    "address":{
      "houseBldgNum":"3"
    },
    "studentName":"JAN K",
    "address":{
      "houseBldgNum":"35"
    }
  }
  </code></pre>
  
  <p>I'm expecting that the two codes should return the same result, but its not.</p>
  
  <p>Thanks in advance!</p>