Deciding on Data Life Cycles
One of the most commonly overlooked aspects of database design is the data life cycle. How long should documents exist in a specific collection? Some collections have documents that should be indefinite—for example, active user accounts. However, keep in mind that each document in the system incurs a performance hit when querying a collection. You should define a TTL, or time-to-live, value for documents in each of your collections.
There are several ways to implement a time-to-live mechanism in MongoDB. One of them is to implement code in your application to monitor and clean up old data. Another method is to utilize the MongoDB TTL setting on a collection, which allows you to define a profile where documents are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access