Back

Create a collection with Attributes using Node JS Appwrite SDK

  • 0
  • Databases
  • Web
  • Cloud
Zainab-Fahim
29 May, 2023, 07:53

Is there a way to create a collection with the respective attributes?

TL;DR
The user wants to know how to create a collection with attributes using the Node.js Appwrite SDK. They mention that the provided examples only show how to create a collection without attributes. They speculate that creating string attributes might be involved and provide an example for creating a string attribute. They also mention that more information can be found in the documentation. The user asks if there is a way to create a collection with attributes. Solution: The user can create a collection with attributes by utilizing the `createCollection` function and specifying the attributes using the appropriate methods (`createStringAttribute`, `createBooleanAttribute`, etc.) for each attribute type. While the
Zainab-Fahim
29 May, 2023, 08:05

there are no examples how to create a collection with multiple attributes

for example the below examples shows how to create a collection, but not with attributes

TypeScript
const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client();

const databases = new sdk.Databases(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;

const promise = databases.createCollection('[DATABASE_ID]', '[COLLECTION_ID]', '[NAME]');

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

thou I understand that it has something to do with creating string attributes

TypeScript
const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client();

const databases = new sdk.Databases(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;

const promise = databases.createStringAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', 1, false);

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});
Bouahaza
29 May, 2023, 08:15
  1. create collection
  2. create attributs one by one
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more