0

I'd like to have a specific expiration time for each document in my collection. I've been following this tutorial and this SO answer (but in Python).

This is how I'm creating an index:

self.coll.create_index([('expireAt', 1)], expireAfterSeconds=0)

This is the document I'm saving to Mongo

document = {'_id': key, 'value': value, 'expireAt': expire_at}
self.coll.replace_one({'_id': key}, document, upsert=True)

I do see the index was created but I can also see expired documents that should have been deleted.

Why?

EDIT: Is it possible that it's since the collection is capped?

IsaacLevon
  • 2,260
  • 4
  • 41
  • 83

1 Answers1

0

For future readers:

  • Check the collection isn't capped
  • use datetime.utcnow() and not datetime.now()
IsaacLevon
  • 2,260
  • 4
  • 41
  • 83