Tip 1: Minimize disk access to memory much faster than disk access. Therefore, the essence of optimization is to minimize disk access. The read speed of the memory is 1 million times faster than that of the disk. Reading a disk takes a long time. Several Simple Methods: Using SSD (solid state drive); Increasing the memory can reduce hard disk reading and
Tip 1: Minimize disk access to memory much faster than disk access. Therefore, the essence of optimization is to minimize disk access. The read speed of the memory is 1 million times faster than that of the disk. Reading a disk takes a long time. Several Simple Methods: Using SSD (solid state drive); Increasing the memory can reduce hard disk reading and
Tip 1: Minimize disk access to memory much faster than disk access. Therefore, the essence of optimization is to minimize disk access.
The read speed of the memory is 1 million times faster than that of the disk. Reading a disk takes a long time. Several Simple Methods: SSD (solid state drive); increased memory can reduce hard disk reading, so that common documents are stored in the memory; tip 2: Using indexes to reduce memory usage indexes is ordered, so you do not have to traverse all items. When querying, the system first checks the index results and loads qualified documents into the memory to reduce memory usage. Tip 3: Do not use indexes everywhere. Note that not all queries can use indexes. Indexes are generally used when the returned results are only a small part of the overall data. Based on experience, once we need to return about half of the data in the set, we should not use indexes.
If you have already created an index for a field and want not to use it for large-scale fuzzy queries (because it may be inefficient to use), you can use natural sorting with {"$ natural ": 1} to force mongodb to disable the index. The natural sorting means that "data is returned according to the storage order on the disk", so that mongodb will not use the index. Tip 4: index overwrite query if only some fields are returned and all these fields can be placed in the index, mong odb can perform index overwrite query ), this type of query does not access the document pointed to by the pointer. Second, the results are directly returned using the indexed data.
Example: db. foo. ensuIndex ({x: 1, y: 1, z: 1}) queries the indexed fields and only returns these fields. Therefore, mongodb does not need to load the entire document. Db, foo. find ({x: ceriteria, y: ceriteria })
This type of query only accesses the index data, but does not access the data of the entire set. Tip 5: Use a composite index to accelerate multiple query queries. You only need to match the first part of the index to use the index, therefore, when creating an index, consider all the fields that these queries depend on. Define the order of index fields based on the frequency of query for each field. Tip 6: organize arrays in layers by establishing a hierarchical document to accelerate scanning, which not only makes them look more organized, it also allows mongodb to quickly query data without indexing. If the document does not have a hierarchical structure, mongodb must traverse each field in the document. Reasonable Use of layers can reduce mongodb's access to fields.
Tip 7: The AND-type query key points assume that you want to query documents that meet the conditions A, B, and c. There are 40 thousand documents that meet the requirements of A, 9 K for B, AND 200 for C, C and B and A should be used to query only 200 records.
That is to say, if a query condition is known to be more demanding, it should be placed at the beginning. Tip 8: The OR type query points are the opposite of the AND query, the most matched query statements are placed at the beginning, because Mongodb needs to match documents that are not in the result set each time.