上QQ阅读APP看书,第一时间看更新
Embedded documents
A better data-modeling solution would be simply to collapse the normalized relationships and fold the related information into embedded (https://docs.mongodb.com/manual/core/data-model-design/#data-modeling-embedding) documents. Using the preceding example, the better solution would appear as follows:
Using embedded documents, with a single query, you can easily obtain a consolidated block of information, which includes the customer name, purchase date, and specifics on the item.
MongoDB also supports creating indexes ( https://docs.mongodb.com/manual/indexes/) on any given field, which boosts query performance. The auto-generated _id field is automatically indexed. It should be noted, however, that creating too many indexes will have a negative impact on performance when writing data.