createCollection
On this page
Creates a new collection.createCollection
command creates a columnstore table.
Syntax
db.createCollection(<name>,{timeseries: {timeField: <string>},rowStore: <boolean>shardKey: <document>sortKey: <document>indexes: <array>columns: <array>preserveJSONKeyOrder: <boolean>from: <document>})
Option |
Type |
Description |
---|---|---|
|
String |
Creates a top-level |
|
Boolean |
When enabled, creates a rowstore table. |
|
Document |
Defines a shard key for the collection at creation in the index format. |
|
Document |
Defines a |
|
Array |
Each document in the array contains an index definition in the type specified in |
|
Array |
Each document in the array represents a top-level column that is created in the table supporting this collection, with an |
|
Boolean |
When enabled, key order is recorded by adding a field named |
|
Boolean |
When enabled, creates a column group index on the collection. Note: Column group indexes are only supported on columnstore tables. |
|
Document |
Specifies an external collection to synchronize data with, in the following format:
|
The following options are not supported in a createCollection
statement:
-
capped
-
timeseries.
metaField -
timeseries.
granularity -
clusteredIndex
-
changeStreamPreAndPostImages
-
size
-
max
-
storageEngine
-
validator
-
validationLevel
-
validationAction
-
indexOptionDefaults
-
viewOn
-
pipeline
-
collation
-
writeConcern
Examples
The following examples show how to use the createCollection
command:
-
Create a collection named exampleC with a field named Code:
db.createCollection("exampleC", {columns: [{ id: "Code", type: "BIGINT NOT NULL" }],}); -
Create a collection supported by a rowstore table:
db.createCollection("exCollection", { rowstore: true }); -
Replicate a collection dbTest.
exampleC from a remote MongoDB® server defined using a link named lnkExample: use dbTest;db.createCollection("exampleC", { from: { link: "lnkExample" } });Refer to Replicate MongoDB® Collections to SingleStore for more information.
-
Create a collection with column group enabled:
db.createCollection("exampleCollection", { columnGroup: true });
Last modified: October 29, 2024