Articles → MONGODB → Time To Live Index In Mongodb
Time To Live Index In Mongodb
Purpose
Syntax
db.collection.createIndex(
{ "date_field_name": 1 },
{ expireAfterSeconds: [number_of_seconds] }
);
Example
db.Sessions.createIndex(
{ "createdAt": 1 },
{ expireAfterSeconds: 1 }
);
Output