1

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

2 Answers 2

3

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') 
1
  • 2
    FYI, you can combine that into one command in the mongo shell: db.adminCommand({logRotate:1}) or even simpler: db.adminCommand('logRotate'). Commented Oct 3, 2017 at 5:49
1

That's because log rotation is not a feature of MongoDB but of the Syslog. Windows has completely different object based way of handling this: the Windows Event Log.

If MongoDB on Windows writes log files similar to the Linux/Unix version, you'd need a third party solution for handling the log rotation. There seems to be LogRotateWin.

2
  • Do you know what LogRotateWin does? I'm a programmer and it looks like something easy to create myself without any overhead? Commented Oct 1, 2017 at 11:15
  • 1
    Well, you could make a program or even a script that checks the age and size of a log file and renames it if it exceeds some limit. Not sure whether MongoDB locks the file or not. Commented Oct 1, 2017 at 11:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.