Operation profiling is disabled by default on MongoDB servers. If profiling information is desired for monitoring purposes, profiling must be enabled in MongoDB. Profiling is enabled on an instance-byinstance and database-by-database basis. So if, for example, profiling for a specific database is desired across a three instance replica set, profiling can be enabled on the primary only or on all three instances, as desired. Profiling on MongoDB does impact database performance, and should be used judiciously in production environments. For more information see
Database Profiling Overhead .
To enable profiling, first connect to the MongoDB instance with the mongo shell. The database user must be assigned a role with the enableProfiler privilege action on the respective database. An example of a built-in role that permits profiler enabling on non-system databases is
dbAdmin.
Switch to the database for which profiling should be enabled. Replace “” below with the name of the database:
use <db-name>To check the current profiling status, execute:
db.getProfilingStatus()Modify the profiling level by executing the
setProfilingLevel command. For example, the following command will enable profiling for all operations taking longer than 250 milliseconds:
db.setProfilingLevel(1, { slowms: 250 }) This is only one example of using the setProfilingLevel command and should not be taken as a recommendation for your database. For full details and options for using this command, see
setProfilingLevel.