MongoDB fixed set (Capped collections)

Source: Internet
Author: User

The MongoDB fixed set (Capped Collections) is a well-performing and fixed-size set, and for a fixed size, we can imagine it is like a ring queue, when the collection space is exhausted, The element that is inserted will overwrite the initial element of the head!

1. Create a fixed collection:

Db.createcollection ("Cappedlogcollection", {capped:true,size:10000})

Specify the number of documents:

Db.createcollection ("Cappedlogcollection", {capped:true,size:10000,max:1000})

Determines whether the collection is a fixed set:

Db.cappedLogCollection.isCapped ()

To convert a collection that already exists to a fixed collection:

Db.runcommand ({"converttocapped": "Posts", size:10000})

2. Fixed set query:

Fixed collection documents are stored in the order in which they are inserted, by default the query is returned in the order in which they were inserted, or the order of return can be adjusted using $natural :

Db.cappedLogCollection.find (). Sort ({$natural:-1})

3. Features of the fixed set:

    can insert and update But the update cannot exceed collection size Span style= "FONT-FAMILY:CALIBRI;" >, , But you can call drop () Delete all rows in the collection but drop After you need to explicitly rebuild the collection.

The maximum value of the previous cappped collection on the three-bit machine is only limited by the system file size on the 482.5m,64 bit.

4. Properties and usage of fixed sets:

Property:

(1) very fast insertion speed for fixed set

(2) The query output speed is very fast according to the insertion order.

(3) The ability to eliminate the earliest data when inserting the latest data

Usage:

(1) store log information

(2) cache Some small amount of documents

MongoDB fixed set (Capped collections)

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.