Working with Database Profiler

1. Enabling Database Profiler

db.setProfilingLevel(1, { slowms: 100 });

2. Setting Profiling Level

LevelEffect
0Disabled
1Slow ops only
2All ops (high overhead)

3. Setting Slow Operation Threshold

SettingDetail
slowmsThreshold in ms (default 100)
sampleRate0.0–1.0 (sample subset)

4. Querying system.profile Collection

db.system.profile.find({millis:{$gt:200}}).sort({ts:-1}).limit(20);

5. Analyzing Slow Queries

FieldUse
millisExecution time
planSummaryCOLLSCAN / IXSCAN + index
docsExamined / keysExaminedEfficiency
nreturnedResult size

6. Understanding Profile Document Structure

FieldDetail
opcommand / query / insert / update / remove
nsNamespace
commandOriginal command document
locksLock acquisition times
storageCache + bytes read

7. Using Profile for Index Optimization

SignalAction
High docsExamined / nreturned ratioAdd or refine index
COLLSCANCreate index
SORT stageAdd sort-friendly index

8. Filtering Profile Results

FilterDetail
filter (4.4+)Persistent filter for what gets profiled
ad-hocfind on system.profile

9. Disabling Profiler

db.setProfilingLevel(0);

10. Managing Profile Collection Size

AspectDetail
CappedDefault 1MB; system.profile
ResizeDisable profiler, drop, recreate as capped with desired size