onsider a collection called coll which contains only the following documents: { _id: 2, a: [ 3, 7 ] } { _id: 3, a: [ 6, 7 ] } { _id: 5, a: [ 4, 4 ] } The following is the result returned by a query, which of the choices below is the query that would generate this result? { _id: 3, a: [ 6, 7 ] } Check all that apply:
题目选项
- A.db.coll.find( { a: { $all: [ 7, 6 ] } } )
- B.db.coll.find( { a: { $all: [ 4, 7 ] } } )
- C.db.coll.find( { a: { $elemMatch: { $gt: 3, $lt: 6 } } } )
答案置信度:高
正确答案:A
解析语言:中文
A 的 $all:[7,6] 要求数组同时含 7 和 6,只有 _id:3(a:[6,7])满足,正好是目标结果。B 的 $all:[4,7] 需要同时含 4 和 7,三个文档都不满足,返回空;C 的 $elemMatch:{$gt:3,$lt:6} 需要存在同时大于 3 且小于 6 的元素,匹配的是 _id:5(元素 4),返回的是另一个文档。