Database

[{"timestamp":new Date("2022-01-01"),"gasUsed":5},{"timestamp":new Date("2022-01-02"),"gasUsed":1},{"timestamp":new Date("2022-01-03"),"gasUsed":10},{"timestamp":new Date("2022-01-04"),"gasUsed":10},{"timestamp":new Date("2022-01-05"),"gasUsed":10}]

Query

db.collection.aggregate([{"$match":{"$and":[{"timestamp":{"$gte":new Date("2022-01-01")}},{"timestamp":{"$lt":new Date("2022-01-03")}}]}},{"$group":{"_id":null,"total_count":{"$sum":1},"total_gas":{"$sum":"$gasUsed"}}}])

Result