MongoDB uses a flexible data model, which means documents in a single collection do not need to have the same structure. Polymorphic data is data in a single collection that varies in document fields or data types.MongoDB使用灵活的数据模型,这意味着单个集合中的文档不需要具有相同的结构。多态数据是指单个集合中的数据,其文档字段或数据类型各不相同。
Generally, documents in a collection are similar in structure but may contain slight variations depending on the application. 一般来说,集合中的文档在结构上是相似的,但根据应用程序的不同,可能会包含轻微的变化。To group similar, non-identical documents in a single collection you can use the Polymorphic and the Inheritance schema design patterns.要将相似、不相同的文档分组到单个集合中,可以使用多态和继承模式设计模式。
These schema designs can improve performance by storing data based on query access patterns, rather than storing data strictly based on document shape.这些模式设计可以通过基于查询访问模式存储数据来提高性能,而不是严格基于文档形状存储数据。
Use Cases用例
title, author, and genre but have additional differing fields depending on their format.title、author和genre字段,但根据其格式,还有其他不同的字段。 | book that provides the shared fields of title, author, and genre across all formats. book父实体的子实体,父实体提供所有格式的title、author和genre等共享字段。 |