MongoDB DEV · Question 104 · Multiple choice

Consider a one-to-many relationship observed between a county and the cities in the county. Which of the following are valid ways to model this relationship in MongoDB? Check all that apply:

Answer options

  1. A.
    Create a collection for the counties. Then in the county document, embed all the cities as an array of cities.
  2. B.
    Create a collection to contain all the cities and all the counties. Then there is no need to add additional references.
  3. C.
    Create a collection for the counties and a collection for the cities. Then in each city document, reference the county the city belongs to.

Answer confidence: High

Correct answer: A, C

Explanation language: Chinese

一对多有两种经典且都有效的建模方式:把“多”的一端内嵌成“一”的一端的数组(county 文档里放城市数组,A),或把关系存在“多”的一端(每个 city 文档保存所属 county 的引用,C),具体选哪种取决于城市数量是否有界、访问模式与更新频率。B 把城市和县混在同一个集合里又不加任何引用字段,等于放弃了关系的表达,不是有效建模。

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 ↗