# Create collection

Create a collection using a vector dimension for quick setup or an explicit schema for custom fields and functions.

SDK: `@zilliz/milvus2-sdk-node@3.0.10` · Tested with Milvus 3.0.6

Canonical documentation: https://milvus-io.github.io/milvus-sdk-node/rest-api/collections/create/

## Section links

- [cURL command](https://milvus-io.github.io/milvus-sdk-node/rest-api/collections/create/#curl-command)
- [Default request](https://milvus-io.github.io/milvus-sdk-node/rest-api/collections/create/#default-request)
- [Sample response](https://milvus-io.github.io/milvus-sdk-node/rest-api/collections/create/#sample-response)
- [Request fields](https://milvus-io.github.io/milvus-sdk-node/rest-api/collections/create/#request-fields)

`POST /v2/vectordb/collections/create`

Replace `https://your-cluster.example.com` with your Milvus endpoint. Set `MILVUS_TOKEN` for authentication or omit the Authorization header on an unauthenticated cluster.

## cURL command

```bash
curl --request POST --url 'https://your-cluster.example.com/v2/vectordb/collections/create' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ${MILVUS_TOKEN}" \
  --data-raw '{
  "dbName": "default",
  "collectionName": "books_demo",
  "dimension": 4,
  "metricType": "COSINE",
  "primaryFieldName": "id",
  "vectorFieldName": "vector"
}'
```

## Default request

```json
{
  "dbName": "default",
  "collectionName": "books_demo",
  "dimension": 4,
  "metricType": "COSINE",
  "primaryFieldName": "id",
  "vectorFieldName": "vector"
}
```

## Sample response

```json
{
  "code": 0,
  "data": {}
}
```

## Request fields

- `dbName` string
  Database name. Operations on collections use default when omitted.
- `collectionName` string (required)
  Name of the collection.
- `dimension` integer
  Number of vector components for quick collection setup. Supply this or an explicit schema.
- `idType` string
  Primary key type for quick setup, such as Int64 or VarChar.
- `autoID` boolean
  Let the server generate primary keys.
- `metricType` string
  Vector distance metric, such as COSINE, L2, or IP.
- `vectorFieldType` string
  Vector data type for quick setup. Choose a type compatible with the metric.
- `consistencyLevel` string
  Read consistency level, such as Strong, Session, or Bounded.
- `primaryFieldName` string
  Primary key field name for quick setup.
- `vectorFieldName` string
  Vector field name for quick setup.
- `schema` object
  Explicit collection schema. Put externalSource and externalSpec inside schema for an external collection.
- `indexParams` array of object
  Index definitions, including the target field, metric and index parameters.
- `params` object
  Additional operation parameters.
- `properties` object
  Map of property names to their new values.
- `description` string
  Human-readable description.

See [`HttpClient.createCollection`](https://milvus-io.github.io/milvus-sdk-node/api-reference/http-client/#createcollection) for the Node.js SDK method.
