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:
题目选项
- A.Create one collection for the stores and embed all the information about the products sold in each store as an array of subdocuments.
- 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.
- 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 标为答案,应是把选项打乱后的误标。)