The MongoDB profiler helps find slow queries and operations by recording detailed information about database activities, so you can improve performance.
Click to reveal answer
beginner
How do you enable the MongoDB profiler to log slow queries only?
Use db.setProfilingLevel(1, { slowms: 100 }) to log queries slower than 100 milliseconds.
Click to reveal answer
beginner
Where does MongoDB store the profiler data?
Profiler data is stored in the system.profile collection inside the current database.
Click to reveal answer
beginner
What command shows the current profiling level in MongoDB?
Run db.getProfilingStatus() to see the current profiler level and slowms threshold.
Click to reveal answer
intermediate
How can you find the slowest queries recorded by the profiler?
Query db.system.profile.find().sort({ millis: -1 }).limit(5) to get the top 5 slowest queries.
Click to reveal answer
What profiling level logs all database operations in MongoDB?
A2
B1
C3
D0
✗ Incorrect
Level 2 logs all operations, including slow and fast queries.
Which collection holds the profiler data in MongoDB?
Asystem.operations
Bsystem.logs
Csystem.slowqueries
Dsystem.profile
✗ Incorrect
Profiler data is stored in the system.profile collection.
How do you set the profiler to log only queries slower than 200ms?
Adb.setProfilingLevel(1, { slowms: 200 })
Bdb.setProfilingLevel(2, { slowms: 200 })
Cdb.setProfilingLevel(0, { slowms: 200 })
Ddb.setProfilingLevel(1)
✗ Incorrect
Level 1 with slowms option logs only slow queries above 200ms.
Which command shows the current profiler status?
Adb.profileStatus()
Bdb.showProfiling()
Cdb.getProfilingStatus()
Ddb.getProfile()
✗ Incorrect
db.getProfilingStatus() returns the current profiling level and slowms.
What does the millis field in profiler data represent?
ANumber of documents scanned
BQuery execution time in milliseconds
CNumber of indexes used
DSize of the result set
✗ Incorrect
The millis field shows how long the query took to run in milliseconds.
Explain how to enable and use the MongoDB profiler to find slow queries.
Think about setting the profiler level and where to find the data.
You got /4 concepts.
Describe the difference between profiling levels 0, 1, and 2 in MongoDB.
Consider what each level records.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the MongoDB profiler when set to capture slow queries?
easy
A. To increase the speed of all queries by caching results
B. To record queries that take longer than a specified time to help optimize performance
C. To delete slow queries from the database
D. To automatically fix slow queries without user intervention
Solution
Step 1: Understand profiler's role
The profiler records queries that exceed a time threshold to help identify slow operations.
Step 2: Identify what profiler does not do
It does not fix or delete queries automatically; it only logs them for review.
Final Answer:
To record queries that take longer than a specified time to help optimize performance -> Option B
Quick Check:
Profiler logs slow queries = To record queries that take longer than a specified time to help optimize performance [OK]
Hint: Profiler logs slow queries for review, not automatic fixes [OK]
Common Mistakes:
Thinking profiler fixes queries automatically
Confusing profiler with query caching
Assuming profiler deletes slow queries
2. Which command correctly sets the MongoDB profiler to log all queries slower than 100 milliseconds?
easy
A. db.setProfilingLevel(2, { slowms: 100 })
B. db.setProfilingLevel(0, { slowms: 100 })
C. db.setProfilingLevel(1, { slowms: 100 })
D. db.setProfilingLevel(1, 100)
Solution
Step 1: Recall profiling levels
Level 1 logs slow queries exceeding the slowms threshold.
Step 2: Check correct syntax
The correct syntax uses level and options object with slowms key, so db.setProfilingLevel(1, { slowms: 100 }) is valid.
Final Answer:
db.setProfilingLevel(1, { slowms: 100 }) -> Option C