Brief description:
When all documents in a collection have a similar but not identical structure, we call it polymorphic pattern
Example:
In actual business, user posts need to be used. The general structure of the posts is the same, but the specific content needs to be displayed differently according to different post types. Therefore, it is more appropriate to use polymorphic mode at this time. A single query can get all posts and their contents, which improves performance. As shown below:
Summary:
Polymorphic mode is used when documents have more similarities than differences. Typical use cases for this pattern design are:
Single view application content management mobile application product catalog
The polymorphic pattern provides an easy-to-implement design that allows queries within a single collection . This is also the schema-less design of mongodb that provides a convenient data construction function.
For more technical articles related to SQL, please visit the SQL Tutorial column to learn!
The above is the detailed content of MongoDB – Polymorphic schema built with schemas. For more information, please follow other related articles on the PHP Chinese website!