w3resource

MongoDB: db.setProfilingLevel() method

db.setProfilingLevel

The db.setProfilingLevel() method is used to modify the current database profiler level used by the database profiling system to capture data about performance. The mongod writes the output of the database profiler to the system.profile collection.

Syntax:

db.setProfilingLevel(level, slowms)

Parameters:

Name Description Required /
Optional
Type
level Specifies a profiling level, which is either 0 for no profiling, 1 for only slow operations, or 2 for all operations. Required integer
slowms Sets the threshold in milliseconds for the profile to consider a query or operation to be slow. Optional integer

Example: MongoDB: db.setProfilingLevel() method

db.setProfilingLevel(1);
db.setProfilingLevel(0);
db.setProfilingLevel(2);
db.setProfilingLevel(2,1);

Output:

> db.setProfilingLevel(1);
{ "was" : 0, "slowms" : 100, "ok" : 1 }
> db.setProfilingLevel(0);
{ "was" : 1, "slowms" : 100, "ok" : 1 }
> db.setProfilingLevel(2);
{ "was" : 0, "slowms" : 100, "ok" : 1 }
> db.setProfilingLevel(2,1);
{ "was" : 2, "slowms" : 100, "ok" : 1 }

Retrieve the restaurants data from here

Previous: db.serverStatus() method
Next: db.shutdownServer() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mongodb/shell-methods/database/db-setProfilingLevel.php