MongoDB DEV · Question 200 · Single choice

Aggregation: Question 11 Consider a collection called agencies that only contains the following documents: { "_id": ObjectId("565385949a9c0d40e8e6f83f"), "type": "A", "agents": [ "red", "blue", "green" ], "files": [ "a", "a", "b", "b" ] } { "_id": ObjectId("565385c39a9c0d40e8e6f840"), "type": "A", "agents": [ "yellow", "blue" ], "files": [ "b" ] } { "_id": ObjectId("5653862c9a9c0d40e8e6f841"), "type": "A", "agents": [ "red", "green" ], "files": [ "a" ] } What is the result of the following aggregation query? db.agencies.aggregate([ { $unwind: "$agents" }, { $unwind: "$files" }, { $match: { files: "b" } }, { $group: { _id: "$type", count: { $sum: 1 } } } ]) Choose the best answer:

Answer options

  1. A.
    { "_id": "A", "count": 8 }
  2. B.
    { "_id": "A", "count": 3 }
  3. C.
    { "_id": "A", "count": 16 }
  4. D.
    { "_id": "A", "count": 5 }
  5. E.
    { "_id": "A", "count": 2 }

Answer confidence: High

Correct answer: A

Explanation language: Chinese

先 $unwind agents 再 $unwind files,会把每条文档展开成 agents 数 × files 数条,再筛 files = b:第一条 3 × 4 = 12 条里 b 占一半共 6 条,第二条 2 × 1 = 2 条全是 b,第三条 files 只有 a 被筛掉,合计 8 条,按 type 分组计数即 8,选 A。

Papers containing this question

This question appears in 3 bank records. Public pages combine identical prompts and options. Selected questions display the highest-confidence record; the others show a short preview. Paper-based learning preserves each record's answer, explanation, and confidence.

AUTHOR · PROJECTS · OPEN SOURCE

Author & MongoDB projects

Building data platforms, MongoDB migration and sync tools, and cloud operations products.

Contact the author for any MongoDB needs.

Contact the author ↗mlhp123@outlook.com

Support the author

If this question bank helps you, optional donations are welcome.

Scan with Alipay to support the authorOpen full-size donation image ↗