I used exact same commands mentioned in below link (expire documents at specific time clocks)
I did
db.log_events.createIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
and then
db.log_events.insert( {
"expireAt": new Date('July 22, 2013 14:00:00'),
"logEvent": 2,
"logMessage": "Success!"
} )
I tested above commands with 4.4.6 and 4.0.5. It works correctly with 4.0.5 and documents are deleted automatically after expiry time but it doesn’t work with 4.4.6.
getIndex output from 4.4.6
[ { v: 2, key: { _id: 1 }, name: '_id_' },
{ v: 2,
key: { expireAt: 1 },
name: 'expireAt_1',
expireAfterSeconds: 0 } ]
getIndex output from 4.0.5
[ { v: 2,
key: { _id: 1 },
name: '_id_',
ns: 'tabletBankingDB.log_events' },
{ v: 2,
key: { expireAt: 1 },
name: 'expireAt_1',
ns: 'tabletBankingDB.log_events',
expireAfterSeconds: 0 } ]
I tried creating index manually as well and saw same results i.e it is working with 4.0.5 but not with 4.4.6.