MongoDB DEV · 题目 198 · 多选

Aggregation: Question 9 Consider a collection called pianoTuners where every document contains the following fields: { "_id": ObjectId("5592b7d02a205cd86441df0a"), "state": "CA", "city": "San Francisco", "tuner": "Jim's Piano Tuners" } You want to find the total number of piano tuners in each state. Which of the following Aggregation operations will accomplish this? Check all that apply:

题目选项

  1. A.
    db.pianoTuners.aggregate([ { $sortByCount: "$state" } ])
  2. B.
    db.pianoTuners.aggregate([ { $group: { _id: "$state", numTuners: { $sum: 1 } } } ])
  3. C.
    db.pianoTuners.aggregate([ { $count: "state" } ])

答案置信度:高

正确答案:A、B

解析语言:中文

$sortByCount: $state 等价于按 state 分组计数再按计数降序输出;$group 配 $sum: 1 同样能得到每个州的调音师数量。$count 只能输出整个管道的文档总数、不按州分组,所以 C 错。

所在套题

此题在题库中有 3 条记录。公开详情合并相同题干和选项;完整公开题展示置信度最高的一条记录,其他题目仅展示摘要。按套学习保留每条记录原有的答案、解析和置信度。

作者 · 作品 · 开源

作者与 MongoDB 作品

专注数据平台、MongoDB 迁移同步与云运维产品研发。

有任何 MongoDB 需求,均可联系作者。

联系作者 ↗mlhp123@outlook.com

支持作者

如果题库对您有帮助,欢迎自愿扫码打赏。

支付宝扫码打赏作者打开打赏原图 ↗