如何在 MongoDB 中一起执行分组、排序和限制聚合?

问题描述 投票:0回答:1

我的收藏是这样的:

"_id": ObjectId(""),
"score": 500,
"year": 2015,
"batch": 1
"location": "Shenzhen"

我正在做的是这样的:

  1. group
    带钥匙
    batch
    year
    location
  2. sort
    score
    asc
  3. 获取每组的
    top 10
    id, year, batch, location, score
mongodb sorting mongodb-query aggregation-framework
1个回答
-2
投票

使用

aggregation
框架:

db.collection.aggregate(
    { $group: { ... } },
    { $sort: {...} },
    { $limit: 10 }
);
© www.soinside.com 2019 - 2024. All rights reserved.