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 automatically deleted after a certain number of seconds or at a specific clock time. Another method for collections where you need only the most recent documents is to implement a capped collection that automatically keeps the size of the collection small.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset