MongoDB DBA · Question 119 · Multiple choice

3. Consider the following documents in a collection called tastes { "favorite_foods": ["Pizza", "Chicken", "Donuts"] } { "favorite_foods": ["Fish", "Pizza", "Fruit salad"] } { "favorite_foods": ["Rice Pudding", "Fish", "Pizza"] } Which document(s) would be returned with the following query? db.tastes.find({ "favorite_foods": { "$all": [ "Pizza", "Fish" ] } }) Check all that apply:

Answer options

  1. A.
    1
  2. B.
    2
  3. C.
    3

Answer confidence: High

Correct answer: B, C

Explanation language: Chinese

$all 要求数组字段同时包含所有给定元素:第 1 个文档的 favorite_foods 是 [Pizza, Chicken, Donuts],没有 Fish,不匹配;第 2 个 [Fish, Pizza, Fruit salad] 和第 3 个 [Rice Pudding, Fish, Pizza] 都同时含 Pizza 和 Fish,会被返回。所以答案是 B、C,即第 2 和第 3 个文档。

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 ↗