Database
[{"event_type":1,time:5,cost:5,text:"hi1"},{"event_type":1,time:5,cost:5,text:"hi2"},{"event_type":1,time:5,cost:5,text:"hi3"},{"event_type":1,time:5,cost:5,text:"hi4"},{"event_type":1,time:5,cost:5,text:"hi5"},{"event_type":1,time:5,cost:5,text:"hi8"},{"event_type":1,time:5,cost:5,text:"hi6"},{"event_type":1,time:5,cost:5,text:"hi7"},]
Query
db.collection.aggregate([{$match:{event_type:{$in:[1,5,10,12]}}},{$group:{_id:"$event_type",avgTime:{$avg:"$time"},avgCost:{$avg:"$cost"},maxCost:{$max:"$cost"},maxTime:{$max:"$time"},texts:{$lastN:{n:5,input:"$text"}}}}])