Skip to content
v2.7

Create collections

Create a new Collection.

POST/databases/{databaseId}/collectionsScope collections.write

SDK: @owbase/node only

Create a new Collection. Before using this route, you should create a new database resource using either a server integration API or directly from your database console.

databaseId string required

Database ID.

collectionId string required

Unique Id. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can’t start with a special char. Max length is 36 chars.

name string required

Collection name. Max length: 128 chars.

permissions string[]

An array of permissions strings. By default, no user is granted with any permissions. Learn more about permissions.

documentSecurity boolean

Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. Learn more about permissions.

enabled boolean

Is collection enabled? When set to ‘disabled’, users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.

attributes object[]

Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, double, boolean, datetime, point, linestring, polygon, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.

indexes object[]

Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial, trigram), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).

description string

Optional description for the collection.

Access: API key with the collections.write scope.

201Success
400Invalid or missing parameter
401No session, no permission on the resource or key without the scope
404Resource in the path not found
429Rate limit

Every error comes as JSON with code, type and message: see Errors.

import { Client, Databases, Permission, Role } from '@owbase/node';
const client = new Client()
.setEndpoint('https://cloud.owbase.dev/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setKey('<YOUR_API_KEY>'); // Your secret API key
const databases = new Databases(client);
const result = await databases.createCollection({
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
name: '<NAME>',
permissions: [Permission.read(Role.any())], // optional
documentSecurity: false, // optional
enabled: false, // optional
attributes: [], // optional
indexes: [], // optional
description: '<DESCRIPTION>', // optional
});
Response201 Created
{
"$id": "5e5ea5c16897e",
"$createdAt": "2020-10-15T06:38:00.000+00:00",
"$updatedAt": "2020-10-15T06:38:00.000+00:00",
"$permissions": [
"read(\"any\")"
],
"databaseId": "5e5ea5c16897e",
"name": "My Collection",
"description": "Movies available in the catalog.",
"enabled": false,
"documentSecurity": true,
"attributes": [],
"indexes": [
{
"$id": "5e5ea5c16897e",
"$createdAt": "2020-10-15T06:38:00.000+00:00",
"$updatedAt": "2020-10-15T06:38:00.000+00:00",
"key": "index1",
"description": "Speeds up lookups by email.",
"type": "primary",
"status": "available",
"error": "string",
"attributes": [],
"lengths": [],
"orders": []
}
],
"bytesMax": 65535,
"bytesUsed": 1500
}

The descriptions on this page come from the server API specification (BSD-3-Clause license), and the examples come from the SDK generator (MIT license). The full notices are in the NOTICE file of the @owbase/web and @owbase/node packages.

Was this page helpful?