22
OCT

Mongo Feature Recap: Size-Limited Collections

With the Mongo database one may create collections of a predefined size, where old data automatically ages out on a least recently inserted basis.  This can be quite handy.   In JavaScript, it is as simple as this:

db.createCollection("mycoll", {capped: true, size:100000})

At collection creation time, specify that the collection is capped and set the size limit (in bytes).

A traditional approach to the problem is to write batch jobs which run periodically and remove old rows from tables. This is ok, but is extra work.  If you don't have a full time DBA and are under the gun in a release cycle, chances are you will put off this cleanup work until later -- and if forgotten, bad things may happen.

This example is consistent with one of the principles we believe will be important in cloud computing: that configuration and maintenance work should be minimized to the greatest extent possible.  In the long run we want to see a world where you write your code, and after that, if it is correct, your work is done.

See the documentation for more information.

| Add a Comment | Back to main page

Categories: db

Comments

1

dwight

I should also mention that the design is such that there is almost no overhead when the objects are ejected.

add a comment