mongodb-fixed set capped collection operation introduction

Source: Internet
Author: User

Fixed collection: Capped collection is a fixed-size collection of excellent performance, eliminating records with LRU algorithms, self-maintaining the insertion order of objects in the collection, creating pre-sized, space-used, heart objects to replace old objects, and keeping up-to-date data.

can be inserted and updated, but updates cannot be exceeded

The size of the collection, or the update fails. Delete is not allowed, but you can call drop () to delete all rows in the collection, but you need to explicitly rebuild the collection after the drop. On a 32-bit machine, the maximum value of a capped collection is only limited by the size of the system file on the 482.5m,64 bit.

Properties and Usage:

Properties: 1, the insertion speed of the fixed set is very fast.

2, in order to insert the query output speed extremely fast.

3, can be inserted in the latest time to eliminate the earliest data.

Usage: 1, store log information.

2. Store a small amount of documentation.

Use

1. You can specify the maximum number of documents that can be stored in collection when creating capped collection. But at this point, it also means
Size, because the size is always checked before checking for Maxrownumber. You can use validate () to see how much space a collection has used to determine how large the size is. Such as:

Db.createcollection ("mycoll", {capped:true, size:100000, Max:100 });  // 100000 = byte

Note: Specify the upper limit of the document, you must specify the size, the document limit is eliminated when the capacity is not full, if full, according to the capacity limit to retire.

> Db.createcollection ("MyCol", {capped:true, Size:100000, Max: -}){ "OK":1 }>db.mycol.valdb.mycol.validate (Db.mycol.valueOf (> Db.mycol.validate ()//Used to view the usage of a fixed collection{    "NS":"Admin.mycol",    "capped":true,    "Max": -,    "firstextent":"0:8c000 Ns:admin.mycol",    "lastextent":"0:8c000 Ns:admin.mycol",    "Extentcount":1,    "datasize":0,    "Nrecords":0,    "lastextentsize":102400,    "padding":1,    "firstextentdetails" : {        "Loc":"0:8c000",        "Xnext":"NULL",        "Xprev":"NULL",        "Nsdiag":"Admin.mycol",        "size":102400,        "Firstrecord":"NULL",        "LastRecord":"NULL"    },    "Deletedcount":2,    "deletedsize":102224,    "nindexes":1,    "Keysperindex" : {        "admin.mycol.$_id_":0    },    "valid":true,    "Errors" : [ ],    "Warning":"Some checks omitted for speed. Use {full:true} option to does more thorough scan.",    "OK":1}> Db.createcollection ("MyCol", {capped:true, Size:100000, Max: -, Autoindexid:false})//There is also a parameter "Autoindexid" when creating collection, and the value can be "true" and "false" to determine whether you need to create an index on "_id"{ "OK":0,"errmsg":"Collection already exists"} > Db.mycol.drop ()true> Db.createcollection ("MyCol", {capped:true, Size:100000, Max: -, Autoindexid:false}) {"OK":1} >

2 . The conversion set converts the test universal set to a fixed set, which is 10000 bytes in size.

Db.runcommand ({converttocapped:"test", Size:10000 });

3. Natural Sorting

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 are inserted, or the return order can be adjusted using $natural.

Db.mycappedcolt.find (). Sort ({"$natural":1});

The parameter 1 indicates the default order, and 1 is the opposite.

4. Determine if the set is a fixed set

Db.colt.isCapped ();

5. View Collection status information

Db.colt.stats ();

mongodb-fixed set capped collection operation introduction

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.