MongoDB DEV · Question 213 · Multiple choice

Consider stores that sell many products and products being sold in many stores. Which of the following are recommended representations for this many-to-many relationship? Check all that apply:

Answer options

  1. A.
    Create one collection for the stores and embed all the information about the products sold in each store as an array of subdocuments.
  2. B.
    Create one collection for the stores and one collection for the products. Then, store an array of references to the products sold in each store in the corresponding store documents.
  3. C.
    Create one collection for the products and embed all the information about the stores in which the product is sold as an array of subdocuments on the product.

Answer confidence: Medium

Correct answer: B

Explanation language: Chinese

多对多推荐用“两个集合 + 引用”表示,即在 store 文档里存放所售商品 _id 的引用数组(C),这样商品信息只保存一份,商品改价改名不会产生同步问题。A、B 把对方实体的全部信息作为子文档嵌入(一个商品在多店销售就要复制多份),会造成大量数据冗余和更新不一致,因此不是推荐做法。(源文件里有考生把 A 标为答案,应是把选项打乱后的误标。)

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 ↗