Database

[{"time":["2018-12-18T20:16:28.800Z","2018-12-18T20:16:28.800Z","2016-11-14T10:16:32.700Z","2016-11-14T10:16:32.700Z","2017-09-17T11:16:54.500Z","2017-09-17T11:16:54.500Z","2016-11-14T10:16:32.700Z"],"foo":[2,5,9,6,3,7,8]},{"time":["2018-12-18T20:16:28.800Z","2018-12-18T20:16:28.800Z","2016-11-14T10:16:32.700Z","2016-11-14T10:16:32.700Z","2017-09-17T11:16:54.500Z","2017-09-17T11:16:54.500Z","2016-11-14T10:16:32.700Z"],"bar":[7,8,9,4,7,7,4]}]

Query

db.collection.aggregate([{$project:{datas:{$map:{input:{$range:[0,{$size:"$time"}]},as:"a",in:{time:{$arrayElemAt:["$time","$$a"]},index:"$$a",data:{$reduce:{input:{$objectToArray:"$$ROOT"},initialValue:{},in:{$cond:[{$in:["$$this.k",["foo","bar"]]},{$arrayToObject:[[{k:"$$this.k",v:{$arrayElemAt:["$$this.v","$$a"]}}]]},{}]}}}}}}}},{$unwind:"$datas"},{$group:{_id:{index:"$datas.index",time:"$datas.time"},time:{$first:"$datas.time"},data:{$mergeObjects:"$datas.data"}}},{$sort:{"_id.index":1}}])

Result