"MongoDB" capped fixed size/quantity collection

Source: Internet
Author: User

Unlike normal collections, fixed collections must be created before they are used, and fixed collections can be created using the Create command. In the shell, you can use the Db.createcollection function:

Create a fixed collection of size 1024 bytes db.createcollection ("capped", {capped:true,size:1024});//Create a size of 1024 bytes, Fixed set db.createcollection ("capped", {capped:true,size:1024,max:100}) with a number of 100 documents;

It is important to note that the size parameter is a required option and the Max parameter is optional. Regardless of which limit is reached, the new document that is inserted then squeezes the old document into the collection, the number of documents in the fixed collection cannot exceed the number of documents set, and the size of the fixed collection cannot exceed the size of the set.


Once a fixed set is created, it cannot be changed, and if you want to modify the properties of a fixed collection, you can only delete and then create it. Therefore, you should carefully consider the size of a large fixed set before you create it.


In addition, you can use the converttocapped command to convert a regular collection to a fixed collection:

Db.runcommand ({converttocapped: "Test", size:1024, max:100});

Note that you cannot convert a fixed collection to a non-fixed collection.


This article is from the architect's path blog, so be sure to keep this source http://lizhuquan0769.blog.51cto.com/2591147/1762000

"MongoDB" capped fixed size/quantity collection

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.