How does mongodb aggregate and return the entire piece of data?

as follows:

after Filter, you are grouped. The two fields are grouping conditions.
however, I just want to get the time in the packet, that is, the data whose fdate is the largest.
how can I do that?

db.SEC_2018_05_12.aggregate([{ $match : { fyear : { $eq : 2018},fmonth:{$eq : 5},fday:{$eq : 12},fhour:{$eq : 17},fmin:{$eq : 8} } }
    ,  { $group: { _id: {dev_id: "$dev_id", data_id: "$data_id"},maxTimeValue: { $max: "$fdate" } } }  ]).pretty()
Mar.11,2021

if you can give some test conditions, it will be easier for others to understand your problem.
first of all, the operator $eq, is not necessary to write most of the time. So your query is equivalent to:

{
  fyear: 1,
  fmonth: 1,
  fday: 1,
  fhour: 1,
  fmin: 1,
  dev_id: 1,
  data_id: 1,
  fdate: -1
}

looks scary enough, doesn't it? But in fact, the previous pile of time itself is just a time.

Menu