InterviewHubPRO
Section Overview
Q35

Question 35 of 60

Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

58%
Databases & System Design•Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

TTL (Time-To-Live) Indexes:

In Simple Words: Automatically deletes documents after a specified duration. Ideal for sessions, caching, and OTP verification codes.

javascript
// Automatically delete session documents 1 hour (3600s) after createdAt:
db.sessions.createIndex(
  { "createdAt": 1 }, 
  { expireAfterSeconds: 3600 }
);