MongoDB DEV · Question 180 · Multiple choice

Consider 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: [ 4, 7 ] } } )
  2. B.
    db.coll.find( { a: { $all: [ 7, 6 ] } } )
  3. C.
    db.coll.find( { a: { $elemMatch: { $gt: 3, $lt: 6 } } } )

Answer confidence: High

Correct answer: B

Explanation language: Chinese

$all [7,6] 要求数组同时包含 6 和 7(顺序无关),只有 {_id:3, a:[6,7]} 满足,结果正好是题目给出的那一个文档。迷惑项 A 的 $elemMatch {$gt:3,$lt:6} 要求同一个元素既大于 3 又小于 6,会命中 {_id:5,a:[4,4]};B 的 $all [4,7] 要求同时含 4 和 7,没有文档满足。

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 ↗