In MySQL, the slow query log is often used as our basis for optimizing queries, is there a similar function in MongoDB? The answer is yes, that is to open the profiling function. The tool collects write operations on MongoDB, cursors, database commands, etc. on the running instance, which can be opened at the database level or at the instance level. The tool writes all the collected to the System.profile collection, which is a capped collection. For more information see: http://docs.mongodb.org/manual/tutorial/manage-the-database-profiler/
Instructions for use:
1:profiling level description
0: Close, do not collect any data.
1: Collect slow query data, default is 100 milliseconds.
2: Collect all data
2: Open Profiling and settings
1: Through MONGO Shell:
#View status: Level and Time
drug: primary> db.getprofilingstatus ()
{"was": 1, "slowms":
View level
drug: primary> db.getprofilinglevel ()
#Set level
drug: primary> db.setprofilinglevel (2)
{"Was": 1, "slowms": M, "OK": 1}
#Set level and time
drug: primary> db.setprofilinglevel (1,200)
{"was": 2, "slo WMS": +, "OK": 1}
If you want to operate on the set below the test set, only the operation in that collection is valid, and if you need to be valid for the entire instance, you need to set up all the sets or
open the arguments when you open them:
2: Do not pass MONGO Shell:
mongod--profile=1--slowms=15 or
add 2 lines in the configuration file: Profile
= 1
slowms = 300
3: Close Profiling
# Close
Drug:primary> db.setprofilinglevel (0)
{"was": 1, "slowms": MB, "OK": 1}
4: Modify the "Slow query log" size
#Close Profiling
drug: primary> db.setprofilinglevel (0)
{"was": 0, "slowms": MB, "OK": 1}
#Remove system. ProFi Le set
drug: primary> db.system.profile.drop ()
true
#Create a new system. Profile Collection
drug: primary> Db.createcollection ("System.profile", {capped: true, size: 4000000})
{"OK": 1}
#Restart Profiling
drug: pri Mary> db.setprofilinglevel (1)
{"was": 0, "slowms": MB, "OK": 1}
Note: To change the size of the secondary system.profile, you must stop secondary, run it as a standalone, and then perform the above steps. When finished, restart the join replica set.
Slow query (system.profile) Description:
For more information, see the following examples: http://docs.mongodb.org/manual/reference/database-profiler/