MongoDB DBA · Question 366 · Multiple choice

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:

Answer options

  1. A.
    db.coll.find( { a: { $all: [ 7, 6 ] } } )
  2. B.
    db.coll.find( { a: { $all: [ 4, 7 ] } } )
  3. C.
    db.coll.find( { a: { $elemMatch: { $gt: 3, $lt: 6 } } } )

Answer confidence: High

Correct answer: A

Explanation language: Chinese

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),返回的是另一个文档。

Papers containing this question

This question appears in 2 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 ↗