Appsmith stores all audit logs for 1 year by default. These logs help administrators track user activities and changes within the platform. However, in some cases, you may want to shorten this retention period, for example, to comply with organizational policies or data privacy requirements.
This guide walks you through changing the Time-to-Live (TTL) setting for audit logs directly in your Appsmith MongoDB database.
Prerequisites
- You must be an Appsmith admin or have access to the MongoDB instance used by Appsmith.
Step 1: Connect to the MongoDB Instance
If you’re running Appsmith via Docker, connect to the MongoDB instance with the following command:
docker exec -it appsmith mongosh <APPSMITH_DB_URL>Replace <APPSMITH_DB_URL> with your MongoDB connection string.
Step 2: Switch to the Correct Database
Once connected, select the Appsmith database:
use <database_name>Usually, the database name is appsmith, but it may differ depending on your setup.
Step 3: Set the New TTL Expiry
Run the following command to change how long audit logs are retained:
db.runCommand({
"collMod": "auditLog",
"index": {
"keyPattern": { "createdAt": 1 },
"expireAfterSeconds": <time_in_secs>
}
})Replace <time_in_secs> with the desired retention duration in seconds.
Examples:
- For 90 days, use
7776000seconds. - For 180 days, use
15552000seconds.
Step 4: Verify the Change
To confirm that the TTL index was updated successfully, run:
db.auditLog.getIndexes()You should see an entry similar to:
{
v: 2,
key: { createdAt: 1 },
name: 'ttl_index_audit_log_created_time',
expireAfterSeconds: 7776000
}Notes
- Changing the TTL value only affects future cleanup operations. Existing expired logs will be deleted automatically by MongoDB’s TTL monitor over time.
- If you ever want to revert to the default 1-year policy, set
expireAfterSecondsto31536000. - For production environments, ensure you back up your instance before making schema changes.