March 2019
Intermediate to advanced
394 pages
11h 4m
English
Time to live (TTL) indexes are used to automatically delete documents after an expiration time. Their syntax is as follows:
> db.books.createIndex( { "created_at_date": 1 }, { expireAfterSeconds: 86400 } )
The created_at_date field values have to be either a date or an array of dates (the earliest one will be used). In this example, the documents will get deleted one day (86400 seconds) after created_at_date.
If the field does not exist or the value is not a date, the document will not expire. In other words, a TTL index silently fails, not returning any errors when it does.
Data gets removed by a background job that runs every 60 seconds. As a result, there is no explicit accuracy guarantee as to how much longer documents ...
Read now
Unlock full access