Do you encounter performance problems when using MongoDB? Here is a summary of the five steps of MongoDB performance optimization, which I hope will help.
First step: Find the slow statement
In general, query statements are too slow and performance problem bottlenecks have a direct relationship, so you can use MongoDB's performance analysis tool to find these slow statements:
Db.setprofilinglevel (1, 100);
Step two: Using explain analysis
These slow statements are diagnosed by using explain. You can also mtools to analyze logs.
Step three: Create an index
After parsing, you need to create a new index to improve the performance of your query. Don't forget that you can create indexes in the background in Mondodb to avoid collections locks and system crashes.
Fourth step: Use sparse indexes to reduce space consumption
If you use sparse documents, and you use the keyword $exists, you can use sparse indexes to reduce the performance of your query by using a space footprint.
Fifth step: Read and write separation
If the read-write is in the master node, the slave node is always in the vacant state, which is a waste. For a report or to search for such a read operation can be fully implemented from the node, so to do is set in connection string into secondarypreferred.
Summary
Although these methods can play a role, the main purpose is to buy some time for the improvement of the architecture.
MongoDB performance Optimization Five simple steps