通过userId分组,得到结果字段为:_id和count
db.my_solitaire.aggregate([{$group: {_id: "$userId", count: {$sum: 1}}}])
通过userId分组得到分组字段和其他想要的字段,得到_id,userName,count
userName 为分组外想要得到的字段
db.my_solitaire.aggregate([{$group: {_id: "$userId", count: {$sum: 1},userName:{"$first":"$userName"}}}])
增加时间条件
db.my_solitaire.aggregate([{$match:{createTime:{$eq:"2023-06-13 09:00:38"}}},{$group: {_id: "$userId", count: {$sum: 1},name:{"$first":"$userName"}}}])