"MongoDB Learning note 26" MongoDB fixed set

Source: Internet
Author: User

The normal collection in MongoDB is dynamic and can automatically grow to accommodate more data, whereas there is another set called a fixed set.

(1) The fixed set needs to realize the explicit creation, the collection size is fixed;

(2) Once the fixed set of space is exhausted, the inserted new document will overwrite the oldest document space, similar to the loop queue;

(3) Fixed set cannot be fragmented;

(4) Fixed set cannot be modified, only rebuild is deleted

First, create a fixed set

Use CreateCollection to create a fixed set of mycollection with a byte size limit of 10000 and a document limit of 100:

> db.createcollection ("mycollection", {capped:true,size:10000,max:100}) {"OK": 1} >


Capped ": Whether the set is fixed;

"Size": Specifies the byte size of the fixed collection;

"Max": Specifies the document limit in the fixed collection;

The new document overwrites the oldest document, whether it is a "size" limit or a "max" limit.

Second, the ordinary set into a fixed set

Use converttocapped to convert an existing set into a fixed collection:

> Db.runcommand ({converttocapped: "foo", "Size": 10000}) {"OK": 1} >

Third, the natural sort of fixed set

A fixed set has a special order, called a natural sort, that returns the order of documents in the result set, which is the sequence of documents on disk.

The default document is sorted from old to new, or you can specify the document from new to old:

> Db.foo.find (). Sort ({$natural: -1}) {"_id": 3, "X": 3} {"_id": 2, "X": 2} {"_id": 1, "X": 1} {" _id ": 0} >


Iv. collection with no _id index

By default:

(1) A common set has a "_id" index. Specifying AUTOINDEXID as False when explicitly creating the collection will not automatically create an index on the _id field;

(2) The fixed set does not have an index of the _id field unless explicitly specified Autoindexid is true at the time of creation, or manually created with ensureindex afterwards;

(3) The index on the _id field must be a unique index;


Five, circular cursors

A circular cursor can only be a special kind of cursor in a fixed set;

(1) When the result set in the cursor is taken out, the cursor does not close, but waits for the new document to be inserted into the cursor;

(2) The loop cursor will be automatically closed after 10 minutes, and it is necessary to automatically execute the query after the cursor is released if you want to use a circular cursor;

(3) A circular cursor cannot be used in a mongodb shell;



This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1601572

"MongoDB Learning note 26" MongoDB fixed set

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.