Home  >  Article  >  Database  >  MongoDB – Polymorphic schema built with schemas

MongoDB – Polymorphic schema built with schemas

步履不停
步履不停Original
2019-07-01 18:02:053701browse

MongoDB – Polymorphic schema built with schemas

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:

MongoDB – Polymorphic schema built with schemas

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn