Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

For attribute schemas built using schemas in MongoDB

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Xiaobian to share with you the use of patterns in MongoDB to build attribute patterns, I hope you have something to gain after reading this article, let's discuss it together!

Brief description:

Go directly to the Know Attributes mode. It is particularly suitable for the following situations:

There is a large document, but it actually has some similar fields, and a subset of these fields have the same characteristics, and finally it is necessary to sort or query these subset fields;

In fact, not all documents will have the required sort field;

or both of these conditions are satisfied.

In fact, for performance reasons, many indexes may be needed to accommodate these subsets in order to optimize the search. But creating more indexes only results in performance degradation. The attribute pattern provides a good solution for this situation.

Examples:

An order data file actually has a lot of time to record, such as creation time, payment time, delivery time, etc. When designing a data structure, of course, the first time you think of it is as follows:

In fact, this design is not too big a problem when the time type is relatively small, but combined with the actual business scenario, the time of an order is certainly not too small. Sometimes, in order to optimize the sorting, we have to establish corresponding indexes. Therefore, the problem now comes. It is possible to establish many indexes one by one according to so many fields, which will reduce the overall query performance. This is when the attribute pattern is appropriate. As shown below:

If the order data structure considers this pattern, it is not necessary to repeatedly index similar subsets of fields, greatly improving query efficiency.

Conclusion:

Attribute schema provides a simpler document index for many similar fields in each document. By moving this subset of data into a key-value subdocument, we can use indeterminate field names, add additional qualifiers to the information, and more clearly describe the relationship between the original fields and values. When we use attribute mode, queries become simpler and faster because fewer indexes are required.

After reading this article, I believe you have a certain understanding of "attribute patterns built using patterns in MongoDB." If you want to know more about it, please pay attention to the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report