MongoDB DEV · 题目 190 · 多选

Consider a collection grades where all documents contain the following fields: { "_id": ObjectId("590b3e2e5e8cdc2dbd114aa4"), "student_name": "Priya", "homework_scores": [ 97, 100, 99, 100, 100, 93, 100 ], "quiz_scores": [ 96, 98, 92 ], "test_scores": [ 100, 99 ] } You would like to perform an aggregation query that computes the average score across homework_scores, quiz_scores, and test_scores and store the average score in a new field. Which of the following aggregation stages can be used to accomplish this? Check all that apply:

题目选项

  1. A.
    $project
  2. B.
    $count
  3. C.
    $addFields

答案置信度:高

正确答案:A、C

解析语言:中文

$project 和 $addFields 都能新增计算字段,可用 $avg 对 $concatArrays 合并后的三组分数求平均并写入新字段。$count 只输出文档条数、不能做逐文档计算,也产生不了新字段——这是本题最容易被误选的干扰项。

所在套题

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

作者 · 作品 · 开源

作者与 MongoDB 作品

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

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

联系作者 ↗mlhp123@outlook.com

支持作者

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

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