[MongoDB] The Capped Collection set of Mongodb databases, mongodbcapped

Source: Internet
Author: User

[MongoDB] The Capped Collection set of Mongodb databases, mongodbcapped

Capped Collection is a set of excellent performance with a fixed size. It executes age-out (aging removal) processing in the LRU (least Recently Used, least Recently Used) rule and insertion sequence, the insertion sequence of objects in the set is automatically maintained.

1. Create a Capped Collection

The size must be specified in advance during creation. If the space is used up, the newly added object will replace the most recent object in the collection. If the size of the colleond ond is exceeded, the update fails. Although deletion is not allowed, you can call the drop method to delete all documents in the set. After deletion, the rebuild set is displayed. On 32 machines, the maximum value of a capped collection is about 482.5 MB, and 64-bit is only limited by the size of the system file.


To convert a common collection to a Capped Collection, you only need to call the convertToCapped () command;


Ii. Usage of Capped Collection

Capped Collection is the preferred Log Mechanism in mongodb. Instead of using log files, mongodb stores log files in the database. The insert speed of objects in a capped collection without indexes is the same as that recorded in the file system.

Some objects are cached in the memory. For example, you need to create an index on the collection for the calculated statistical information, because the cache is often used to read more than write.

You can use the age-out feature of capped collection to save the effort of writing a crontab script to perform manual archiving.

Iii. Notes

1. If there are more writes than reads, it is best not to create an index on it;

2. Using natual ordering can effectively retrieve Recently inserted elements, because the capped collection ensures that the natural sorting is the insertion order.

3. capped collection cannot be shard.

4. You can specify the maximum number of documents that can be stored in the collection when creating a capped collection.





Related Article

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.