MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
TTL (Time-To-Live) and Partial Indexes in MongoDB.
senior LevelMost AskedDatabases & SQL
In Simple Words:
- TTL Index: Automatically deletes documents after a specified number of seconds (
expireAfterSeconds: 3600). Ideal for temporary OTP verification codes, shopping cart sessions, and log retention. - Partial Index: Indexes only documents matching a filter expression (
partialFilterExpression: { active: true }), reducing index memory size.