createCollection() - Creates a collection

Creates a new collection with the specified characteristics.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. createCollection(name,tableSpec)

Command arguments

name
Specifies a collection name. It must be alphanumeric with no special characters except $.
tableSpec
This optional parameter specifies the selection criteria for indexes. The options are as follows:
_id
Specifies ID definition. It must be one of the following data types:
  • $int
  • $long
  • $number
  • $date
  • $timestamp
  • $string: length
  • $binary: length
compress (YES | NO) YES | NO)
Specifies whether to compress the collection.
tablespace
Specifies the name of the table space.
inline
Specifies the bufferpool space usage. It is of type integer.
systemTime (sysStartField | sysEndField)
Specifies the system time for sysStartField and sysEndField variables.
businessTime (busStartField | busEndField )
Specifies the business time for busStartField and busEndField variables.

Example

Example 1: Create a collection called "media" with _id of type SQL BIGINT.
db.createCollection(“media”, {_id: “$long”)}) 
Sample output:
Collection: TEST."media" created. Use db.media.