In other words, is there a difference between
db.eventlog.createIndex( { "lastModifiedDate": 1 }, { expireAfterSeconds: 3600 } )
and
db.eventlog.createIndex( { "lastModifiedDate": -1 }, { expireAfterSeconds: 3600 } )
?
The docs do not seem to mention anything regarding this.
It doesn't matter.
With a single field index - The order won't matter. If they are close together in ascending order, they will also be close together in descending order.
How TTL works
//find the expireAfterSeconds value from collection indexes
var expireAfterSeconds = db.eventlog.getIndexes().filter(function(i){
return i.hasOwnProperty('expireAfterSeconds');
})[0].expireAfterSeconds;
// epoch time
var startTime = new Date(1970,0,1);
// end time
var endTime = new Date(Date.now() - expireAfterSeconds*3600);
db.eventlog.remove({lastModifiedDate: { $gt: startTime, $lte: endTime }});
Reference: ttl.cpp source
Full TTL explanation: http://hassansin.github.io/working-with-mongodb-ttl-index
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With