Mithil Poojary
Mithil Poojary

Reputation: 301

MongoDB TTL does not work on atlas but works fine on localhost

I followed this article - https://docs.mongodb.com/manual/tutorial/expire-data/
I created the index on atlas first. It was added successfully. But the documents weren't deleted as per expiry.
I used the same method on localhost mongo shell, and it worked fine.

I added this index

{ "expiresAt": 1 }, { expireAfterSeconds: 0 } 

where expiresAt is a Date object in my document.

This is the document I expected to be deleted.

_id    :5f55f440058cdd3754907255
name    :"first"
language    :"Plain Text"
content    :"Some text"
createdAt    :2020-09-07T08:50:08.708+00:00
expiresAt    :2020-09-07T08:51:08.709+00:00
__v    :0

Upvotes: 0

Views: 1649

Answers (1)

Mithil Poojary
Mithil Poojary

Reputation: 301

I asked the same question on mongodb forums.
Pavel_Duchovny was very patient and helpful. He answered here.

So while using the web UI - You need to place field name under FIELDS: { "expiresAt": 1 }

And under OPTIONS: { expireAfterSeconds: 0 }

Upvotes: 1

Related Questions