Bird
Raised Fist0
MongoDBquery~10 mins

Profiler for slow queries in MongoDB - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable the profiler for slow queries in MongoDB.

MongoDB
db.setProfilingLevel([1])
Drag options to blanks, or click blank then click option'
A2
B0
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using level 0 disables profiling.
Level 3 is not a valid profiling level.
2fill in blank
medium

Complete the code to set the slow operation threshold to 100 milliseconds.

MongoDB
db.setProfilingLevel(1, { slowms: [1] })
Drag options to blanks, or click blank then click option'
A100
B10
C1000
D10000
Attempts:
3 left
💡 Hint
Common Mistakes
Setting slowms too high misses slow queries.
Setting slowms too low may log too many queries.
3fill in blank
hard

Fix the error in the command to retrieve slow queries from the system profiler collection.

MongoDB
db.system.profile.find({ [1]: { $gt: 100 } })
Drag options to blanks, or click blank then click option'
AexecutionTime
BtimeMillis
Cmillis
DdurationMillis
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names like 'durationMillis' or 'timeMillis'.
Using 'executionTime' which is not a valid field.
4fill in blank
hard

Fill both blanks to query slow operations longer than 200 ms and sort by duration descending.

MongoDB
db.system.profile.find({ [1]: { $gt: 200 } }).sort({ [2]: -1 })
Drag options to blanks, or click blank then click option'
AdurationMillis
Bmillis
DexecutionTime
Attempts:
3 left
💡 Hint
Common Mistakes
Using different field names for filter and sort.
Sorting ascending instead of descending.
5fill in blank
hard

Fill all three blanks to enable profiling for slow queries over 150 ms and retrieve them sorted by duration.

MongoDB
db.setProfilingLevel([1], { slowms: [2] }); db.system.profile.find({ [3]: { $gt: 150 } }).sort({ [3]: -1 })
Drag options to blanks, or click blank then click option'
A1
B150
Cmillis
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using profiling level 2 which profiles all queries.
Using inconsistent field names for filtering and sorting.

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

  1. Step 1: Understand profiler's role

    The profiler records queries that exceed a time threshold to help identify slow operations.
  2. Step 2: Identify what profiler does not do

    It does not fix or delete queries automatically; it only logs them for review.
  3. Final Answer:

    To record queries that take longer than a specified time to help optimize performance -> Option B
  4. 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

  1. Step 1: Recall profiling levels

    Level 1 logs slow queries exceeding the slowms threshold.
  2. Step 2: Check correct syntax

    The correct syntax uses level and options object with slowms key, so db.setProfilingLevel(1, { slowms: 100 }) is valid.
  3. Final Answer:

    db.setProfilingLevel(1, { slowms: 100 }) -> Option C
  4. Quick Check:

    Level 1 + slowms option = db.setProfilingLevel(1, { slowms: 100 }) [OK]
Hint: Use level 1 with slowms in options object for slow query logging [OK]
Common Mistakes:
  • Using level 2 to log only slow queries (it logs all queries)
  • Passing slowms as second argument without object
  • Setting level 0 which disables profiling
3. Given the following profiler query:
db.system.profile.find({ millis: { $gt: 50 } })

What does this query return?
medium
A. All queries that took more than 50 milliseconds
B. All queries that took less than 50 milliseconds
C. All queries that took exactly 50 milliseconds
D. All queries regardless of execution time

Solution

  1. Step 1: Understand the query filter

    The filter { millis: { $gt: 50 } } selects documents where the millis field is greater than 50.
  2. Step 2: Interpret millis field meaning

    Millis records query execution time in milliseconds, so this finds queries slower than 50ms.
  3. Final Answer:

    All queries that took more than 50 milliseconds -> Option A
  4. Quick Check:

    Filter $gt 50 means queries > 50ms = All queries that took more than 50 milliseconds [OK]
Hint: $gt means greater than, so queries slower than threshold [OK]
Common Mistakes:
  • Confusing $gt with $lt (greater than vs less than)
  • Thinking it returns queries equal to 50ms
  • Assuming it returns all queries
4. You run db.setProfilingLevel(1, { slowms: '100' }) but no slow queries are logged. What is the problem?
medium
A. The profiler only logs queries slower than 1000ms by default
B. Profiling level 1 does not log slow queries
C. You must restart MongoDB after setting profiling level
D. The slowms value should be a number, not a string

Solution

  1. Step 1: Check slowms parameter type

    slowms expects a number, but '100' is a string, causing it to ignore the threshold.
  2. Step 2: Understand profiling behavior

    Profiling level 1 logs slow queries, no restart needed, and default slowms is 100ms if not set.
  3. Final Answer:

    The slowms value should be a number, not a string -> Option D
  4. Quick Check:

    slowms must be numeric, not string = The slowms value should be a number, not a string [OK]
Hint: Use number type for slowms, not string quotes [OK]
Common Mistakes:
  • Passing slowms as string instead of number
  • Thinking profiling level 1 disables logging
  • Believing MongoDB needs restart after setting profiler
5. You want to find the top 3 slowest queries recorded by the profiler. Which query will correctly return these?
hard
A. db.system.profile.find().sort({ millis: -1 }).limit(3)
B. db.system.profile.find().sort({ millis: 1 }).limit(3)
C. db.system.profile.find({ millis: { $lt: 3 } })
D. db.system.profile.find().limit(3)

Solution

  1. Step 1: Sort queries by execution time descending

    Sorting by millis: -1 orders queries from slowest to fastest.
  2. Step 2: Limit results to top 3

    Using limit(3) returns only the first three documents after sorting.
  3. Final Answer:

    db.system.profile.find().sort({ millis: -1 }).limit(3) -> Option A
  4. Quick Check:

    Sort descending + limit 3 = db.system.profile.find().sort({ millis: -1 }).limit(3) [OK]
Hint: Sort by millis descending, then limit 3 for slowest queries [OK]
Common Mistakes:
  • Sorting millis ascending returns fastest queries
  • Filtering millis less than 3 returns wrong data
  • Not sorting before limiting results
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard