title: Find matching array items in MongoDB document
body: <p>I am developing a web app using Codeigniter and MongoDB.
  In the database I got a document that look like this:</p>
  
  <pre><code>{
      "_id": {
          "$id": "4f609932615a935c18r000000"
      },
      "basic": {
          "name": "The project"
      },
      "members": [
          {
              "user_name": "john",
              "role": "user",
              "created_at": {
                  "sec": 1331730738,
                  "usec": 810000
              }
          },
          {
              "user_name": "markus",
              "role": "user",
              "created_at": {
                  "sec": 1331730738,
                  "usec": 810000
              }
          }
      ]
  }
  </code></pre>
  
  <p>I need to search this document using both user_name and role. Right now when I am using the below code I get both. I only want to get array items matching both user_name and role.</p>
  
  <pre><code>$where = array (
  
      '_id' =&gt; new MongoId ($account_id), 
  
      'members.user_id' =&gt; new MongoId ($user_id),
  
      'members.role' =&gt; $role
  
  );
  
  $this -&gt; cimongo -&gt; where ($where) -&gt; count_all_results ('accounts');
  </code></pre>