Text and TTL Indexes
A text index supports $text search. A TTL index deletes documents automatically after a time, useful for sessions and logs.
Example
db.articles.createIndex({ body: "text" })
db.articles.find({ $text: { $search: "mongodb tutorial" } })
db.sessions.createIndex({ createdAt: 1 }, { expireAfterSeconds: 3600 })Exercise
Expire after an hour.
expireAfter: 3600
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.