Suppose you have a collection named alpha that contains only the following documents: { "_id": 1, "region": "NW1", "leads": 1, "email": "mlangley@co1.com" } { "_id": 2, "region": "NW1", "leads": 1, "email": "jpicoult@co4.com" } { "_id": 3, "region": "NW1", "leads": 2, "email": "zzz@company2.com" } { "_id": 4, "region": "SE1", "leads": 8, "email": "mary@hssu.edu" } { "_id": 5, "region": "SE2", "leads": 4, "email": "janet@col.edu" } { "_id": 6, "region": "SE2", "leads": 2, "email": "bill@uni.edu" } { "_id": 7, "region": "SE2", "leads": 4, "email": "iii@company1.com" } { "_id": 8, "region": "SW1", "leads": 1, "email": "phil@co3.com" } { "_id": 9, "region": "SW1", "leads": 2, "email": "thomas@company.com" } { "_id": 10, "region": "SW2", "leads": 5, "email": "sjohnson@uchi.edu" } How many documents will be returned by the following Aggregation query? db.alpha.aggregate([ { "$group": { "_id": "$region" , "count": { "$sum": 1 }, "leads": { "$max": "$leads" } } } , { "$match": { "leads": { "$gt": 3 } } } ]) Choose the best answer:
题目选项
- A.0
- B.1
- C.2
- D.3
- E.4
答案置信度:高
正确答案:D
解析语言:中文
$group 按 region 分组并取每组 leads 的最大值:NW1=2、SE1=8、SE2=4、SW1=2、SW2=5。$match 保留 leads>3 的分组后只剩 SE1、SE2、SW2 三组,因此返回 3 个文档。