title: MongoDB find all dictionary in array of a document
body: <pre><code>{
      "name": "sample_config222",
      "data": [
          {
              "id": 1,
              "first_name": "George",
              "last_name": "Bluth",
          },
          {
              "id": 2,
              "first_name": "Janet",
              "last_name": "Bluth",
          },
      ]
  }
  </code></pre>
  
  <p>I want find all dictionaries that matches <code>key: value</code> in a document. Here is the two things, </p>
  
  <ol>
  <li><p>Find the document with <code>"name": "sample_config222"</code> </p></li>
  <li><p>Search dictionaries in array of document that we selected in <code>1</code>.</p></li>
  </ol>
  
  <p>I tried </p>
  
  <pre><code>db.config.find({name: "sample_config"}, {"data": { $elemMatch: { "last_name": "Bluth" } } })
  </code></pre>
  
  <p>It is showing only one dictionary which is the first one </p>
  
  <pre><code>{
      "name": "sample_config222",
      "data": [
          {
              "id": 1,
              "first_name": "George",
              "last_name": "Bluth",
          }
  }
  </code></pre>
  
  <p>And also it is getting results from other document contains <code>"last_name": "Bluth"</code></p>
  
  <p>I tried with <code>$and</code> which is showing entire document. </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>There is similar question <a href="https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection">here</a> which uses <code>$elematch</code> returns only one dictionary in array. But i want get all dicts whichever matches the query</p>