How to delete system.profile collection from a MongoDB?

I am profiling the db queries in MongoDB. I followed this link. I am trying to delete all data from the collection system.profile so I can start benchmarking different queries again. I tried the following code but it gives an error

CONSOLE SYNTAX

> db.system.profile.remove({})

ERROR

cannot delete from system namespace

How do I delete all data from that collection? If that's not possible, how can I start profiling from the beginning?


Solution 1:

Firstly, turn off the profiling by setting its level to 0.

db.setProfilingLevel(0)

Then you can simply drop the collection.

db.system.profile.drop()

Now you are free to go and start it all over.

Solution 2:

To riff off of the accepted answer, it is at times helpful to do in a single line:

db.setProfilingLevel(0); db.system.profile.drop(); db.setProfilingLevel(2);

I'm also finding that setting the size of system.profile to 10MB (or larger) rather than its default 1MB is quite helpful:

db.setProfilingLevel(0); db.system.profile.drop(); db.createCollection("system.profile", {capped: true, size: 10 * 1024 * 1024}); db.setProfilingLevel(2);