Fork Copy [ { "$match": { "created_at": { "$gte": "ISODate(\"2019-03-18T00:00:00.000+0000\")", "$lte": "ISODate(\"2019-03-18T23:59:59.999+0000\")" } } }, { "$group": { "_id": { "publisher_id": "$publisher_id" }, "count": { "$sum": 1.0 }, "revenue": { "$sum": "$payout" } } }, { "$lookup": { "from": "impressions", "let": { "parent_publisher_id": "$_id.publisher_id" }, "pipeline": [ { "$match": { "$expr": { "$and": [ { "$eq": [ "$publisher_id", "$$parent_publisher_id" ] }, { "$gte": [ "$date", 190318.0 ] }, { "$lte": [ "$date", 190318.0 ] } ] } } }, { "$group": { "_id": null, "impressions": { "$sum": "$impressions" } } }, { "$project": { "_id": 0.0 } } ], "as": "impressions_data" } }, { "$unwind": { "path": "$impressions_data" } } ]