ttl index mongodb code example
Example 1: mongodb index
db.collection.createIndex( { name: -1 } )
Example 2: mongodb conditional expire
let keys = { lastModifiedDate: -1 };
let options = {
expireAfterSeconds: 3600,
partialFilterExpression: { pending: true }
};
db.getCollection("collection").createIndex(keys, options);