Windows – Mongo forcing a log rotation on Windows

logrotatemongodbwindows

I was wondering how I can setup log rotation for a MongoDB on Windows.

I'm only reading it for Linux and Unix based systems in the documentation. Does anyone know how I can set this up?

https://docs.mongodb.com/manual/tutorial/rotate-log-files/#forcing-a-log-rotation-with-sigusr1

Best Answer

I found out that MongoDB has it's own logRoation for Windows build in.

Rotate the log file by issuing the logRotate command from the admin database in a mongo shell:

use admin
db.runCommand( { logRotate : 1 } )

https://docs.mongodb.com/manual/tutorial/rotate-log-files/#rotate-the-log-file

EDIT:

Stennie told in the comment below that you can even do

db.adminCommand( { logRotate : 1 } )

or

db.adminCommand('logRotate')