How to query the maximum value of updateAt in each userId

  mongodb, question
 userId: OjbectId,
 updatedAt: Date

I am a rookie, ask for advice.

If you know how to write in SQL, the same principle applies to MongoDB. This is a very common grouping aggregation query. The answer is below, but I still hope you can try to search for the answer online and exercise your ability to solve problems independently.

 {$group: {_id: "$userId", maxUpdatedAt: {$max: "$updatedAt"}}}

UseaggregationThe$maxOperator can easily get the answer.