Database
[{"_id":"eyxwapfhiezfe664ec","orderPrice":20,"responseTime":10,"createdAt":ISODate("2021-01-15T17:16:25.844Z")},{"_id":"eyxwlcfeojrfeoc","orderPrice":50,"responseTime":10,"createdAt":ISODate("2021-01-15T17:16:25.844Z")},{"_id":"eyxwapfhiseflflpsssc","orderPrice":20,"responseTime":7,"createdAt":ISODate("2021-01-15T17:16:25.844Z")},{"_id":"eyxwapfhdfghkdfps","orderPrice":12,"responseTime":5,"createdAt":ISODate("2021-01-16T17:16:25.844Z")},{"_id":"eyxwapfhiezzefllc","orderPrice":30,"responseTime":10,"createdAt":ISODate("2021-01-16T17:16:25.844Z")}]
Query
db.collection.aggregate([{"$facet":{"metricsTotal":[{$group:{_id:null,sumOrderPrice:{$sum:"$orderPrice"},avgOrderPrice:{$avg:"$orderPrice"},sumResponseTime:{$sum:"$responseTime"},avgResponseTime:{$avg:"$responseTime"}}}],"metricsByDay":[{$group:{_id:{$dateFromParts:{"year":{"$year":"$createdAt",},"month":{"$month":"$createdAt",},"day":{"$dayOfMonth":"$createdAt",}}},sumOrderPrice:{$sum:"$orderPrice"},avgOrderPrice:{$avg:"$orderPrice"},sumResponseTime:{$sum:"$responseTime"},avgResponseTime:{$avg:"$responseTime"}}}]}}])