MongoDB DEV · 题目 83 · 多选

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:

题目选项

  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" }

答案置信度:高

正确答案:A、B、C

解析语言:中文

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

所在套题

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

作者 · 作品 · 开源

作者与 MongoDB 作品

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

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

联系作者 ↗mlhp123@outlook.com

支持作者

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

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