Help me please in TTL index

records.create_index(“Date”, expireAfterSeconds=20)

insertme = {


"Name": "PERU_Yash",

"Other": "Owner"



print(“ALL DONE”)

i am using pymongo for excuting, but after 20 seconds record is not deleting

Please tell where i am wrong

Welcome to the MongoDB Community Forums @Josean_Vallejo !

You may need to wait longer than 20 seconds for the document to be removed.

Per Timing of the Delete Operation for TTL indexes:

The background task that removes expired documents runs every 60 seconds . As a result, documents may remain in a collection during the period between the expiration of the document and the running of the background task.

Because the duration of the removal operation depends on the workload of your mongod instance, expired data may exist for some time beyond the 60 second period between runs of the background task.

Did your document get removed eventually?


1 Like

Thanks sir, but this code didn’t worked,

After that used datetime.utcnow() and that worked perfectly