[SERVER-9305] Enabling adding expireAfterSeconds to convert to a TTL index Created: 09/Apr/13  Updated: 06/Dec/22  Resolved: 01/Feb/22

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Backlog - Storage Execution Team
Resolution: Duplicate Votes: 10
Labels: ttl
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
duplicates SERVER-13938 Allow TTLMonitor to use existing inde... Closed
is duplicated by SERVER-35844 TTL index should be able to include _... Closed
Related
is related to SERVER-13938 Allow TTLMonitor to use existing inde... Closed
is related to SERVER-6701 TTL expiration using _id index Closed
Assigned Teams:
Storage Execution
Participants:

 Description   

The challenge with this is in the way system.indexes is implemented. It is not possible to easily grow the index spec document.

This would allow you to take any existing index and have it work as a TTL index.

Should test this also works with _id indexes.



 Comments   
Comment by Louis Williams [ 01/Feb/22 ]

Indexes can now be converted to TTL as of SERVER-13938 in MongoDB 5.1. This is documented here.

We will not support this on _id indexes.

Comment by leonn paiva [ 31/May/15 ]

Add TTL on _id would be the best. If you need to have very fast writes in a scenario with a big load of data.

Comment by Kevin Pulo [ 10/Oct/14 ]

A possible workaround is to create another index in the reverse order, with TTL, and then once that's built drop the original index. The downside is you need enough space and time to build the index again.

ie. instead of trying to "convert" {a:1} to TTL, do something like

db.foo.ensureIndex({a:-1}, {expireAfterSeconds: x})
db.foo.dropIndex({a:1})

If you feel like being clean you could then do

db.foo.ensureIndex({a:1}, {expireAfterSeconds: x})
db.foo.dropIndex({a:-1})

to get back to having the "right" index, even though the reverse one should work just as well.

Comment by Ryan Witt [ 21/Oct/13 ]

+1

Comment by Eliot Horowitz (Inactive) [ 05/Jun/13 ]

Its not trivial to add to collmod

Generated at Thu Feb 08 03:20:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.