Mongo Playground

Configuration

[{"_id":ObjectId("5a934e000102030405000000"),"title":"Sensor 1","totals":[{timestamp:ISODate("2022-09-10T06:00:00Z"),count:200},{timestamp:ISODate("2022-09-12T06:00:00Z"),count:1},{timestamp:ISODate("2022-09-12T07:00:00Z"),count:2},{timestamp:ISODate("2022-09-12T08:00:00Z"),count:3},{timestamp:ISODate("2022-09-12T09:00:00Z"),count:4},{timestamp:ISODate("2022-09-12T10:00:00Z"),count:5}]},{"_id":ObjectId("5a934e000102030405000001"),"title":"Sensor 2"}]

Query

db.collection.update({},[{"$set":{"totals":{"$ifNull":["$totals",[]]}}},{"$set":{"totals":{"$filter":{"input":"$totals","cond":{"$gte":["$$this.timestamp",ISODate("2022-09-11T14:00:00Z")]}}}}},{$set:{totals:{"$cond":{"if":{"$in":[ISODate("2022-09-12T10:00:00Z"),"$totals.timestamp"]},"then":{"$map":{"input":"$totals","in":{"$cond":{"if":{"$eq":["$$this.timestamp",ISODate("2022-09-12T10:00:00Z")]},"then":{"$mergeObjects":["$$this",{count:{"$add":[{"$ifNull":["$$this.count",0]},123]}}]},"else":"$$this"}}}},"else":{"$concatArrays":["$totals",[{"timestamp":ISODate("2022-09-12T10:00:00Z"),"count":123}]]}}}}}],{multi:true})

Result