title: Complex MongoDB find queries on large documents in Java
body: <p>How do I make a MongoDB query using BasicDBObjects in Java, when I wish to find all documents that contain an array of nested documents, where one of those nested documents meets all the specified criteria?</p>
  
  <p>Taking the example data:</p>
  
  <pre><code>[
     {
        "_id":"blood_0",
        "type":"O",
        "list":[
           {
              "firstname":"John",
              "lastname":"Smith",
              "zipcode":"12345"
           },
           {
              "firstname":"John",
              "lastname":"Hamilton",
              "zipcode":"54627"
           },
           {
              "firstname":"Ben",
              "lastname":"Brick",
              "zipcode":"12345"
           },
           {
              "firstname":"William",
              "lastname":"Tell",
              "zipcode":"15487"
           }
        ]
     },
     {
        "_id":"blood_1",
        "type":"AB",
        "list":[
           {
              "firstname":"Mary",
              "lastname":"Smith",
              "zipcode":"12345"
           },
           {
              "firstname":"John",
              "lastname":"Henry",
              "zipcode":"54624"
           },
           {
              "firstname":"Jacob",
              "lastname":"Tell",
              "zipcode":"19283"
           },
           {
              "firstname":"William",
              "lastname":"Dirk",
              "zipcode":"15999"
           }
        ]
     }
  ]
  </code></pre>
  
  <p>If I only want to return the objects that contain a contact in the list that meets the criteria of <strong>firstname = William</strong>, <strong>lastname = Tell</strong> how would I go about doing that?  The queries I am doing are not grouping the criteria, so I would get two results where I actually only should be getting one.</p>
  
  <p>How would I do the same query but also checking for <strong>type = AB</strong>, as well as the other criteria, which would return no results?</p>