title: How to perform AND operation in Mongodb for a query on nested array of objects
body: <p>I have the following records:  </p>
  
  <pre><code>Record 1:  
  {
      "status": "active",
      "users": [
          {
              "name": "foo",
              "status": "a"
          },
          {
              "name": "foo",
              "status": "b"
          }        
      ]
  }
  
  Record 2:  
  {
      "status": "active",
      "users": [
          {
              "name": "bar",
              "status": "a"
          },
          {
              "name": "foo",
              "status": "b"
          }        
      ]
  }
  </code></pre>
  
  <p>Now, I wish to return only those records in which the <code>user.name</code> is "foo" and the <code>user.status</code> is "a" - That is I need to get Record 1 back since it satisfies my requirements.</p>
  
  <p>How do I do the AND operation on the array within the record to achieve this?
  I tried the following query:</p>
  
  <pre><code>{
      "$and": [
          {
              "users.name": "foo"
          },
          {
              "users.status": "a"
          }
      ]
  }
  </code></pre>
  
  <p>but I get both the records - I need only the first record (since in the users array, it has an entry where the name is "foo" AND the status is "a").</p>
  
  <p>Any clues?</p>