Capped Collection is a well-performing set of fixed-size collections that perform used (aging-out) processing in LRU (least recently age-out, least recently used) rules and insertion order, automatically maintaining the order in which objects in the collection are inserted.
first, create capped Collection
When created, you specify the size beforehand, and if the space is exhausted, the newly added object will replace the nearest object in the collection. If the update exceeds the Collectiond size, the update fails. Although deleting is not allowed, you can call the drop method to delete all the documents in the collection. After deletion, you want to display the Rebuild collection. On 32 machines, the maximum value of a capped collection is approximately 482.5m,64 bit only limited by the size of the system file.
A normal Collection is converted to capped Collection, as long as the converttocapped () command is called;
Second, the use of Capped collection
Capped Collection is the preferred logging mechanism in MongoDB, and MongoDB does not use log files, but log files are stored in the database. Inserting an object in a capped collection that does not have an index is equivalent to the log speed recorded in the file system.
Caching some objects in memory, such as computed statistics, typically requires an index on the collection, because using the cache is often more read than write.
You can take advantage of the age-out features of the capped collection, eliminating the task of writing crontab scripts to perform manual archiving.
Third, the matters needing attention
1. If you write more than read, it is best not to create an index on it;
2, using natual ordering can effectively retrieve the most recently inserted element, because capped collection can guarantee that the natural sort is the order of insertion.
3. Capped collection cannot be shard.
4. You can specify the maximum number of documents that can be held in collection when creating capped collection.
Capped collection collection of "MongoDB" MongoDB database