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
- A.0
- B.1
- C.2
- D.3
- 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)。