'Can I use the timestamp portion of a MongoDB document ID for a TTL index?

According to this documentation, you can create a TTL index on a document field containing a date value. It seems to imply you have to create a field just to hold the timestamp of when the document was generated. However, this documentation shows that you can get the generation time of a document from its document ID. So is there any way to use that information for a TTL index, without creating a new field just to hold the generation time data which already exists in the document ID?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source