Database

[{"_id":ObjectId("178768747638364736373637"),"start_time":ISODate("2019-02-03T12:00:00.000Z"),"finish_time":ISODate("2019-02-03T12:01:00.000Z"),"a":1},{"_id":ObjectId("266747364736363536353555"),"start_time":ISODate("2019-02-03T12:00:00.000Z"),"finish_time":ISODate("2019-02-03T12:03:00.000Z"),"a":2},{"_id":ObjectId("367463536453623546353625"),"start_time":ISODate("2019-02-03T12:00:00.000Z"),"finish_time":ISODate("2019-02-03T12:08:00.000Z"),"a":1}]

Query

db.collection.aggregate([{$setWindowFields:{output:{totalCount:{$sum:1}}}},{"$project":{totalCount:1,duration:{"$divide":[{"$subtract":["$finish_time","$start_time"]},1000]},Percentile95Index:{"$multiply":[0.95,"$totalCount"]}}}])

Result