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?
MongoDB Profiler is a built-in tool which gives you the actual query level insights. It allows you to analyze all the queries which are being run by the database system.
To delete all documents in a collection, pass an empty document ( {} ). Optional. To limit the deletion to just one document, set to true . Omit to use the default value of false and delete all documents matching the deletion criteria.
db. dropDatabase() the command is used to drop an existing database. This command will delete the currently selected database. If you have not selected any database, then it will delete the default 'test' database.
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.
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);
Keep in mind that the profile collection is capped!
In order to create a collection keeping more records about queries, recreate it with a desired size.
db.setProfilingLevel(0)
db.system.profile.drop()
db.createCollection( "system.profile", { capped: true, size: 1024*1024*10 } )
db.setProfilingLevel(1, { slowms: 500 })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With