- Reference >
- Database Commands >
- Administration Commands >
- create
create¶
On this page
Definition¶
-
create
¶ Explicitly creates a collection.
create
has the following form:create
has the following fields:Field Type Description create
string The name of the new collection. capped
Boolean Optional. To create a capped collection. specify true
. If you specifytrue
, you must also set a maximum size in thesize
field.autoIndexId
Boolean Optional. Specify false
to disable the automatic creation of an index on the_id
field. Before 2.2, the default value forautoIndexId
wasfalse
.size
integer Optional. The maximum size for the capped collection. Once a capped collection reaches its maximum size, MongoDB overwrites older old documents with new documents. The size
field is required for capped collections.max
integer Optional. The maximum number of documents to keep 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 use this limit, ensure that thesize
limit is sufficient to contain the documents limit.flags
integer Optional. .. versionadded:: 2.6
Set to
0
to disable theusePowerOf2Sizes
allocation strategy for this collection, or1
to enableusePowerOf2Sizes
. Defaults to1
unless thenewCollectionsUsePowerOf2Sizes
parameter is set tofalse
.For more information on the
autoIndexId
field in versions before 2.2, see _id Fields and Indexes on Capped Collections.The
db.createCollection()
method wraps thecreate
command.
Considerations¶
The create
command obtains a write lock on the
affected database and will block other operations until it has
completed. The write lock for this operation is typically short
lived. However, allocations for large capped collections may take
longer.
Example¶
To create a capped collection limited to 64 kilobytes, issue the command in the following form: