日拱一卒,功不唐捐
知识点
- $match:条件匹配
- $group :分组
- $sort :排序
- $limit :限制结果返回数量
“order” collection存储了用户购买记录,需要获取A店铺每个用户首次购买记录。
userId | create_time | itemId | price | shop_name |
---|---|---|---|---|
123456 | 2020-06-01 11:53:21.000Z | abc123789 | 235 | A |
123456 | 2020-06-06 12:03:51.000Z | asd789123 | 279 | A |
MongoDB 查询:组内分组排序
db.getCollection('order').aggregate(