- Reference >
- Database Commands >
- Administration Commands >
- create
create¶
On this page
Definition¶
-
create¶ Explicitly creates a collection.
createhas the following form:createhas the following fields:Field Type Description createstring The name of the new collection. cappedBoolean Optional. To create a capped collection. specify true. If you specifytrue, you must also set a maximum size in thesizefield.autoIndexIdBoolean Optional. Specify falseto disable the automatic creation of an index on the_idfield. Before 2.2, the default value forautoIndexIdwasfalse.sizeinteger 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 sizefield is required for capped collections.maxinteger Optional. The maximum number of documents to keep in the capped collection. The sizelimit 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 thesizelimit is sufficient to contain the documents limit.For more information on the
autoIndexIdfield in versions before 2.2, see _id Fields and Indexes on Capped Collections.The
db.createCollection()method wraps thecreatecommand.
Note
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: