MongoDB DEV · Question 66 · Single choice

Given a collection "coll" composed of only these documents: { "_id": 1 , "a": 1 , "b": [ 3 ] } { "_id": 11 , "a": "5" , "b": [ 5, 3, 7 ] } { "_id": 111 , "a": 1 , "b": [ 3, 5 ] } { "_id": 12 , "a": "5" , "b": [ "alpha", 5 ] } Which of these queries will return only the following documents? { "_id": 11, "a": "5", "b": [ 5, 3, 7 ] } { "_id": 111 , "a": 1 , "b": [ 3, 5 ] } Choose the best answer:

Answer options

  1. A.
    db.coll.find({ "b": { "$and" : [ 3, 5 ] } })
  2. B.
    db.coll.find({ "b": { "$in" : [ 3, 5 ] } })
  3. C.
    db.coll.find({ "b": [ 3, 5 ] })
  4. D.
    db.coll.find({ "b": 3, "b": 5})
  5. E.
    db.coll.find({ "b": { "$all" : [ 3, 5 ] } })

Answer confidence: High

Correct answer: E

Explanation language: Chinese

$all [3,5] 要求数组字段 b 同时包含 3 和 5,命中 b=[5,3,7](_id 11)和 b=[3,5](_id 111),正好是题目要求返回的两个文档。B 的 $in 只需匹配其中一个元素,会多返回 b=[3]、b=["alpha",5] 等文档;A、C、D 的写法(把数组当整体比较、重复键)语义都不对。

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 ↗