In some situations, LogMessages are not automatically deleted from the collection, causing performance issues. To resolve this issue, a cleanup script was introduced.
Mongo Command- db.collection.remove() :
The db.collection.remove() method is used to delete collection data from collection.
The syntax for this command is as follows: db.collection.remove()
Script:
A batch file is provided which when executes deletes logmessageentity collection data from Mongo DB whose name is provided in the batch file connection string:-
cd \Program Files\MongoDB\Server\3.2\bin set /p Count= Enter the no. of days since when the logging should be removed: mongo.exe AC-SVR024:27017/Znode_9_0_0_Custom_LogMessage --eval "db.logmessageentity.remove({ CreatedDate:{ $lte : new Date(ISODate().getTime() - 1000 * 86400 * "%Count%")} });" pause
Steps for executing batch file :
Edit the batch file and modify the connection string.
Modify server name and Mongo DB name.
Provide the number of days from which the log should be cleared.
Save the batch file and execute it.
The logmessageentity collection data generated X days ago will be cleared. Here X represents the number of days provided.