Spring Data MongoDB how to assign expiration time programmatically

前端 未结 2 1511
春和景丽
春和景丽 2021-01-17 15:45

I couldn\'t find in any of the Spring-Data documents, what is the way to assign expiration time to a document in MongoDB?

2条回答
  •  北海茫月
    2021-01-17 16:37

    Thanks, but does the whole document is expired and deleted or just the field?

    According to the MongoDB Documentation https://docs.mongodb.com/manual/core/index-ttl/ The TTL index is used to remove documents from a collection.

    So, the entire document will be deleted and not uniquely the field indexed.

    Nb : The index has to be positioned on a Date Field, else the TTL will not be apply

    regards

提交回复
热议问题