db.getCollection('streams').aggregate(
[{$group: {
  _id: '$game_id',
  total: {
    $sum: '$viewer_count'
  }
}},  {$lookup: {
  from: 'games',
  localField: '_id',
  foreignField: 'id',
  as: 'Game'
}}, {$replaceRoot: {
  newRoot: {
    $mergeObjects: [
      {
        $arrayElemAt: [
          '$Game',
          0
        ]
      },
      '$$ROOT'
    ]
  }
}}, {$project: {
  Game: 0,
  box_art_url: 0,
  _id: 0,
  id: 0
}}, {$group: {
  _id: null,
  items: {
    $addToSet: {
      name: '$name',
      total: '$total',
      g: "$g"
    }
  }
}}, {$unwind: {
  path: "$items"
}}, {$sort: {
  "items.total": -1
}}, {$group: {
  _id: null,
  items: {
    "$push": "$items"
  }
}}, {$project: {
  tmp: {
    $arrayToObject: {
      $zip: {
        inputs: [
          '$items.name',
          '$items.total'
        ]
      }
    }
  }
}}, {$replaceRoot: {
  newRoot: '$tmp'
}}, {$addFields: {
  __time__: '$$NOW'
}}, {$merge: {
  into: 'final',
  on: '_id',
  whenMatched: 'replace',
  whenNotMatched: 'insert'
}}]
)