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