MongoDB DEV · Question 83 · Multiple choice

The travel collection contains the following documents: { "_id" : ObjectId("5ab0615f5b3e785dd5fa3705"), "name" : "Randy Salazar", "age" : 60, "visited" : [ "Israel", "São Tomé and Príncipe", "Malta", "Ethiopia" ] } { "_id" : ObjectId("5ab0615f5b3e785dd5fa3706"), "name" : "Lillian Hernandez", "age" : 38, "visited" : [ "Canary Islands" ] } { "_id" : ObjectId("5ab0615f5b3e785dd5fa3707"), "name" : "Peter Gregory", "age" : 22, "visited" : [ "Afghanistan" ] } { "_id" : ObjectId("5ab0615f5b3e785dd5fa3709"), "name" : "Russell Simpson", "age" : 41, "visited" : [ "United Arab Emirates", "Cayman Islands", "Norway", "Ukraine", "Slovakia" ] } You perform the following aggregation command: db.travel.aggregate([ { "$unwind": "$visited" }, { "$sample": { "size": 3 } } ]) Which of the following could be part of the result set returned by this command? Check all that apply:

Answer options

  1. A.
    { "_id" : ObjectId("5ab0615f5b3e785dd5fa3707"), "name" : "Peter Gregory", "age" : 22, "visited" : "Afghanistan" }
  2. B.
    { "_id" : ObjectId("5ab0615f5b3e785dd5fa3709"), "name" : "Russell Simpson", "age" : 41, "visited" : "Norway" }
  3. C.
    { "_id" : ObjectId("5ab0615f5b3e785dd5fa3709"), "name" : "Russell Simpson", "age" : 41, "visited" : "United Arab Emirates" }

Answer confidence: High

Correct answer: A, B, C

Explanation language: Chinese

$unwind "$visited" 后每个"人+国家"成为独立文档,$sample {size:3} 再从这些文档中随机抽 3 条,因此 A、B、C 都是 unwind 后真实存在的文档,都可能(甚至同时)出现在结果里。$sample 只保证随机抽取、不保证某个文档一定被选中,"可能出现在结果中"三者都成立。

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 ↗