Deleting log file

my mongod.log file has been increased a lot and due to that mongodb has been stopped and not able to serve any request. It has grown up to 90 GB and there is no space on server now. I want to clean the file to free up the space but couldn’t find the option to do so. I found a post saying roate the file, but my server doesn’t have any space. And rotating will create one more copy of 90 GB file. So, I have 2 questions

  1. How can I clean my mongod.log file to free up the space
  2. If I delete the file, will it get created again automatically?
    Please help


Firstly, you may want to check why the log grew so big, suspecting you have high logging level, you could check the log level with the below:

rotating will not create a new copy, it will simply rename the existing one with a timestamp when the log rotation was initiated and start writing to a fresh mongo.log, you can then gzip the old log file or move the it to another disk if you have free space or you can delete it at this point if it’s no longer needed.

For your second question if the old log entries are not needed, I have also tried in my testing environment to empty the logfile entirely by issuing the below:

cat /dev/null > mongod.log

and then rotating the logfile as below:
mongo --eval ‘db.adminCommand( { logRotate : “server” } )’

and found that mongod process rotated the emptied file and created a fresh mongod.log and started writing to it.


I have the same issue, I had already check the server log level and it is in default level 0. I have also an hourly logrotation with logrotate.
Our /var/log/ partition could be full after 10 minutes with multi-process scripts using 64 workers.
Our MongoDB server shutdown when it couldn’t write in log partition.

Is there a way to handle this more than those two tips?

Thanks @Mohamed_Elshafey for your reply. I will check the things as you suggested.