title: How to perform $lookup aggregation query deep into field in mongodb?
body: <p>How to perform properly <strong>$lookup</strong> aggregation query <strong>deep into field</strong> in mongodb?</p>
  
  <p><strong>templates</strong></p>
  
  <pre><code>{
      "_id": ObjectID("589888769ffec515d86f3e6c"),
      "tpl_name": "t1",
      "tpl_user": "some"
  },
  {
      "_id": ObjectID("589888769ffec123386f3222"),
      "tpl_name": "t2",
      "tpl_user": "some"
  }
  </code></pre>
  
  <p><strong>subscriptions</strong></p>
  
  <pre><code>{
    "_id": ObjectID("58c182ed320386f56a518efb"),
      "data": {
          "template": "589888769ffec515d86f3e6c",
          "email": "some.email@gmail.com"
      }
  },
  {
      "_id": ObjectID("58c182ed320386f56a518e7f"),
      "data": {
          "template": "589888769ffec515d86f3e6c",
          "email": "some.email@gmail.com"
      }
  }
  </code></pre>
  
  <p>Need to get list of templates with subscriptions in it. </p>
  
  <p>I tried to get it like that.</p>
  
  <pre><code>db.collection('templates').aggregate([
      {$match: { 'tpl_user': tpl_user.id }},
      {
          $lookup: {
              from: "subscriptions",
              localField: "_id",
              // tried to use foreignField like that
              foreignField: "data.template",
              as: "subscriptions"
          }
      },
  ])
  </code></pre>
  
  <p>But no dice. Query returns empty subscriptions array.</p>