title: Get filtered count of elements in array from $lookup along with the whole document
body: <p>I have this query in MongoDB:</p>
  
  <pre><code>db.emailGroup.aggregate([
      {
          "$lookup": 
          {
              "from": "link",
              "localField": "_id",
              "foreignField": "emailGroupId",
              "as": "link"
          },
      },
      {
          "$unwind": "$link"
      },
      {
          "$match": {
               'link.originalLink': ""
          }
      },
      {
          "$group" : {
              _id: '$_id',
              link: {
                  $push: '$link'
              }
          }
      },
      {
          "$project": { 
              "size": { 
                  "$sum": { 
                      "$map": { 
                          "input": "$link", 
                          "as": "l", 
                          "in": { 
                              "$size": {
                                  "$ifNull": [
                                      "$$l.linkHistory", []
                                  ]
                              }
                          } 
                      } 
                  } 
              }
          }
      }
  ])
  </code></pre>
  
  <p>EmailGroup has partId field. I use $lookup to "join" other collection for sum her fields. I need group by partId field and sum custom field "size" for partId groups. Is this possible? Extra question: How can I add emailGroup fields to query result?</p>
  
  <p>Sample documents:</p>
  
  <p>emailGroup:</p>
  
  <pre><code>{
      "_id" : ObjectId("594a6c47f51e075db713ccb6"),
      "partId" : "f56c7c71eb14a20e6129a667872f9c4f",
  }
  </code></pre>
  
  <p>link: </p>
  
  <pre><code>{
      "_id" : ObjectId("594b96d6f51e075db67c44c9"),
      "originalLink" : "",
      "emailGroupId" : ObjectId("594a6c47f51e075db713ccb6"),
      "linkHistory" : [ 
          {
              "_id" : ObjectId("594b96f5f51e075db713ccdf"),
          }, 
          {
              "_id" : ObjectId("594b971bf51e075db67c44ca"),
          }
      ]
  }
  </code></pre>