Set TTL for some (not all) documents in a collection

Hi, I am a newbie for MongoDB, I just wonder if it is possible to set TTL to certain documents in a collection, rather than having to create a TTL index that will apply the expiration timestamp for all document in a collection?

Welcome to the MongoDB Community @Bo_Yuan!

TTL expiry is based on matching an indexed Date field in a collection. Documents without the TTL date field (or a valid BSON Date value for this field) will not expire.

Another option would be configuring your TTL index to Expire Documents at a Specific Clock Time, with a far future date for the documents you do not want to delete.



This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.