MongoDB DEV · Question 81 · Single choice

Your collection, foo, contains the following documents: { "_id": ObjectId("5579adff1066d4f57a1db7e4"), "a": 10, "b": [ 7, 1, 2 ] } { "_id": ObjectId("5579adff1066d4f57a1db7e5"), "a": 2, "b": [ 4, 3, 2 ] } { "_id": ObjectId("5579ae001066d4f57a1db7e6"), "a": 4, "b": [ 5, 5, 6 ] } { "_id": ObjectId("5579ae001066d4f57a1db7e7"), "a": 2, "b": [ 6, 4, 7 ] } You perform the following command: db.foo.aggregate([ { $match: { a: { $lt: 10 } } }, { $unwind: "$b" }, { $group: { _id: 1, a_tot: { $sum: "$a" } } } ]) How many documents will be in the result set of this aggregation command? Choose the best answer:

Answer options

  1. A.
    0
  2. B.
    1
  3. C.
    2
  4. D.
    3
  5. E.
    4

Answer confidence: High

Correct answer: B

Explanation language: Chinese

$match {a:{$lt:10}} 命中 a=2、4、2 三个文档,$unwind "$b" 后每个文档展开成 3 条共 9 条,最后 $group {_id:1} 把所有文档归成一组,因此结果集只有 1 个文档(其 a_tot = 2+4+2 各重复 3 次,共 24)。

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 ↗