Too Long; Didn't Read
How to Erase Expired Docs Automatically with MongoDB (TTL index) I needed to delete some documents that I saved in MongoDB after some time. My wife told me that MongoDB already has that mechanism built-in. A background thread reads the values in the index and removes expired documents from the collection (usually every minute) The indexed field must be BSON date type or an array of BSON dates. If a document does not contain the indexed field, the document will not expire.