title: How to retrieve all matching elements present inside array in Mongo DB?
body: <p>I have document shown below:</p>
  
  <pre><code>{
    name: "testing",
    place:"London",
    documents: [ 
                          {   
                              x:1,
                              y:2,
                          },
                          {
                              x:1,
                              y:3,
                          },
                          {
                              x:4,
                              y:3,
                          }
              ]
      }
  </code></pre>
  
  <p>I want to retrieve all matching documents i.e. I want o/p in below format:</p>
  
  <pre><code>{
      name: "testing",
      place:"London",
      documents: [ 
                          {   
                              x:1,
                              y:2,
                          },
                          {
                              x:1,
                              y:3,
                          }
  
              ]
      }
  </code></pre>
  
  <p>What I have tried is :</p>
  
  <pre><code>db.test.find({"documents.x": 1},{_id: 0, documents: {$elemMatch: {x: 1}}});
  </code></pre>
  
  <p>But, it gives first entry only.</p>