Thursday 19 February 2015

What is capped collection?


Capped collection is a fixed size collection, that automatically overwrites its oldest entries when it reaches its maximum size.

Options
Filed
Type
Description
capped
Boolean
Optional. ‘true’ indicates it is a capped collection. For capped collections, you must also set maximum size in ‘size’ field
autoIndexId
Boolean
Optional. Specify false to disable the automatic creation of an index on the _id field.
size
Number
Optional. Specifies a maximum size in bytes for a capped collection. The size field is required for capped collections, and ignored for other collections.
max
Number
Optional. The maximum number of documents allowed in the capped collection. The size limit takes precedence over this limit. If a capped collection reaches its maximum size before it reaches the maximum number of documents, MongoDB removes old documents. If you prefer to use this limit, ensure that the size limit, which is required, is sufficient to contain the documents limit.
usePowerOf2Sizes
boolean
Optional. It is the default allocation strategy for all collections. Set to false to disable the usePowerOf2Sizes allocation strategy for this collection. By setting usePowerOf2Sizes, you ensure that MongoDB will allocate space for documents in sizes that are powers of 2. Smalles allocation for a document is 32. So it grows like 32, 64, 128, 256….


For example
> db.createCollection("address", { capped : true, size : 5242880, max : 5000 } )
{ "ok" : 1 }

Above command creates a collection named address with a maximum size of 5 megabytes and a maximum of 5000 documents.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment