MongoDB log rotation in Windows
Original Question or Issue:
We noticed that our MongoDB log file keeps growing and doesn't create a new one.
Environment:
- Product - FileCloud Server
- Version - Any
- Platform - Windows
Steps to Reproduce:
MongoDB is installed on a Windows server.
Error or Log Message:
Growing MongoDB log file.
Defect or Enhancement Number:
Cause:
Resolution or Workaround:
Connect to your FileCloud server via RDP
Create a bat file in <Drive_Letter>:\xampp\MongoRotate.bat
Append the content below and save the file :
<Drive_Letter>:\xampp\mongodb\bin\mongosh.exe --host "127.0.0.1:27017" admin --eval "db.adminCommand({ logRotate: 1 })" --quiet
The MongoDB log file should rotate if you double click the bat file.
Open the Windows Task Scheduler and create a Basic Task that runs daily at night to execute the bat file.
Notes:
The MongoDB connection string should be adapted to your environment.