Query profiler

Record a database's slow operations in system.profile.

Record a database's slow operations in system.profile to find them later. It works on any node.

Requirements

  • A user with dbAdmin on the database.

Turn the profiler on

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

Level 1 records the operations slower than slowms milliseconds; level 2, all of them; level 0 turns it off.

Read what was recorded

JavaScript
db.system.profile.find().sort({ ts: -1 }).limit(10);

Check

A query slower than 50 ms appears in system.profile with its plan and its duration.

Common problems

  • Level 2 records every operation and loads the node; use it only for a while.

See also