MongoDB DEV · 题目 213 · 多选

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:

题目选项

  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.

答案置信度:中

正确答案:B

解析语言:中文

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

所在套题

此题在题库中有 3 条记录。公开详情合并相同题干和选项;完整公开题展示置信度最高的一条记录,其他题目仅展示摘要。按套学习保留每条记录原有的答案、解析和置信度。

作者 · 作品 · 开源

作者与 MongoDB 作品

专注数据平台、MongoDB 迁移同步与云运维产品研发。

有任何 MongoDB 需求,均可联系作者。

联系作者 ↗mlhp123@outlook.com

支持作者

如果题库对您有帮助,欢迎自愿扫码打赏。

支付宝扫码打赏作者打开打赏原图 ↗