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:
题目选项
- A.{ "_id" : ObjectId("5ab0615f5b3e785dd5fa3707"), "name" : "Peter Gregory", "age" : 22, "visited" : "Afghanistan" }
- B.{ "_id" : ObjectId("5ab0615f5b3e785dd5fa3709"), "name" : "Russell Simpson", "age" : 41, "visited" : "Norway" }
- 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 只保证随机抽取、不保证某个文档一定被选中,"可能出现在结果中"三者都成立。