- 将出版者文档嵌入到书籍文档中将导致出版者数据重复

- 为避免重复出版商数据,请使用引用
- 使用引用时,关系的增长决定了将引用存储在何处。 如果每个出版商的图书数量很少且增长有限,则有时将图书参考存储在出版商文档中可能会很有用。 否则,如果每个发布者的书籍数量不受限制,则此数据模型将导致可变的,不断增长的数组,如以下示例所示 ```json { name: “O’Reilly Media”, founded: 1980, location: “CA”, books: [123456789, 234567890, …] }
{ _id: 123456789, title: “MongoDB: The Definitive Guide”, author: [ “Kristina Chodorow”, “Mike Dirolf” ], published_date: ISODate(“2010-09-24”), pages: 216, language: “English” }
{ _id: 234567890, title: “50 Tips and Tricks for MongoDB Developer”, author: “Kristina Chodorow”, published_date: ISODate(“2011-05-06”), pages: 68, language: “English” }
- 为了避免可变的,增长的数组,请将出版商参考存储在书籍文档中```json{_id: "oreilly",name: "O'Reilly Media",founded: 1980,location: "CA"}{_id: 123456789,title: "MongoDB: The Definitive Guide",author: [ "Kristina Chodorow", "Mike Dirolf" ],published_date: ISODate("2010-09-24"),pages: 216,language: "English",publisher_id: "oreilly"}{_id: 234567890,title: "50 Tips and Tricks for MongoDB Developer",author: "Kristina Chodorow",published_date: ISODate("2011-05-06"),pages: 68,language: "English",publisher_id: "oreilly"}
