createCollection

On this page

Creates a new collection. SingleStore Kai creates a collection implicitly on write. By default, the 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

timeseries.timeField

String

Creates a top-level DATETIME(6) field and marks it with SERIES TIMESTAMP. Additionally, it creates a SORT KEY on this field, which accelerates time-related queries.

rowStore

Boolean

When enabled, creates a rowstore table.

shardKey

Document

Defines a shard key for the collection at creation in the index format. For example, {a:1}.

sortKey

Document

Defines a SORT KEY for the collection in the index format. For example, {a:1}.

indexes

Array

Each document in the array contains an index definition in the type specified in createIndex. For example, {name:"indexExample", key:{a:1}}.

columns

Array

Each document in the array represents a top-level column that is created in the table supporting this collection, with an id and a type. If the type is not specified, it is assumed to be JSON by default. For example: {id:"mycolumn",type:"BIGINT NOT NULL"}.

preserveJSONKeyOrder

Boolean

When enabled, key order is recorded by adding a field named $$ into each level of the documents. This key order is retrieved when the document is read through the API. By default, SingleStore alphabetizes the JSON key order.

columnGroup

Boolean

When enabled, creates a column group index on the collection. Column group indexes improve the performance of queries where the entire document is projected. Refer to How the Columnstore Works for more information.

Note: Column group indexes are only supported on columnstore tables.

from

Document

Specifies an external collection to synchronize data with, in the following format:

{
link: <string>
database: <string>
collection: <string>
}
  • link (Required): Specifies the name of the link created using the createLink command.

  • database (Optional): Name of the source database. If not specified, the current database is used.

  • collection: (Optional): Name of the source collection. If not specified, the current collection is used.

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

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK