title: Filter array in subdocument array field
body: <p>I am trying to fetch an element from an array in the MongoDB. I think the aggregation filter is the right one to apply. But I tried million times already, I still cannot find where is the problem. Could you give me hand?</p>
  
  <p>MongoDB sample data:</p>
  
  <pre><code>{
      "_id" : 12,
      "items" : [
              {
                      "columns" : [
                              {
                                      "title" : "hhh",
                                      "value" : 10
                              },
                              {
                                      "title" : "hahaha",
                                      "value" : 20
                              }
                      ]
              },
              {
                      "columns" : [
                              {
                                      "title" : "hiii",
                                      "value" : 50
                              }
                      ]
              }
      ]
  }
  </code></pre>
  
  <p>My solution:</p>
  
  <pre><code>    db.myCollection.aggregate([
     {
        $project: {
           items: {
              $filter: {
                 input: "$items",
                 as: "item",
                 cond: { $eq: [ "$$item.columns.title", "hahaha" ]}
              }
           }
        }
     }
  ]).pretty()
  </code></pre>
  
  <p>My result:</p>
  
  <pre><code>{
      "_id" : 15,
      "items" : [
              {
                      "columns" : [ ]
              },
              {
                      "columns" : [ ]
              }
      ]
  }
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>{
      "_id" : 15,
      "items" : [
              {
                      "columns" : [
                              {
                                      "title" : "hahaha",
                                      "value" : 20
                              }
                      ]
              },
              {
                      "columns" : []
              }
      ]
  }
  </code></pre>
  
  <p>I have checked the Mongo reference:
  <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/filter/#example" rel="nofollow noreferrer">https://docs.mongodb.com/manual/reference/operator/aggregation/filter/#example</a></p>
  
  <p>MongoDB version:3.4.1<br>
  Testing environment: Mongo Shell</p>