$dev4life = "Software Development Blog"

MongoDB - Capped Collections

- Create collection
- View collection stats
- Convert existing collection to capped

One of the best features of MongoDB is ability to create capped collections.  Capped collection is a fixed size collection that deletes the old data while the new one is added.  This process is done seamlessly in the background.  Anyone familiar with MySQL and large data sets (over few Gigs) will know the frustration.  Administrator could simply set a collection to be of certain size (in bytes) and the database will take care of everything else.  There are however couple of things to note.  As of right now, capped collections can not be sharded.  Also, MongoDB pre-allocated space for capped collection.

// Create collection

// Convert to capped collection (50MB capped)

// Check if converted to capped

// Create a new capped collection
db.createCollection("capped_collection", { capped: true, size: 50000000 });

// Check collection stats (shows size, count, index information, etc)

mongodb,capped collection, convertToCapped, createCollection, database, isCapped, stats

Post a Comment