Mongodb aggregate

  mongodb, question

Question: There is a set of data similar to the following
{“sn”:”18160481″,”status”:1,”updateTime”:1542691932103}
{“sn”:”18160482″,”status”:2,”updateTime”:1542691932113}
{“sn”:”18160483″,”status”:2,”updateTime”:1542691932123}
{“sn”:”18160484″,”status”:3,”updateTime”:1542691932133}

How can I get the latest updateTime through aggregate and count the number with status 2?

I don’t know if I understand what I mean to you. The latestupdateTimeIf you are referring to the pressstatusAfter grouping, each group is the latest. That is how it is written:

db.table.aggregate([
 {$group: {_id: "$status", updateTime: {$max: "$updateTime"}, count: {$sum: 1}}}
 ]);