Capped collection collection of "MongoDB" MongoDB database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.