Skip to content
Back

Is there any way to create collection programatically ?

  • 0
  • Flutter
  • Cloud
Rabin Acharya
18 Mar, 2025, 16:33

I have a user case where I need to create a new collection for every businesses that register with my app, is there any way that I can do that programatically without having to copy paste collection id ?

TL;DR
Developers can create collections programmatically using a server-side SDK like the one for Dart or Node.js. By triggering a function when a new document is added to the main collection, developers can automate the creation of new collections for each registered business. The Appwrite documentation provides a guide on creating collections programmatically: https://appwrite.io/docs/references/cloud/server-nodejs/databases#createCollection.
Kenny
18 Mar, 2025, 16:34

Sure! Using a server side sdk, you have the ability to create databases, collections, attributes, etc.

https://appwrite.io/docs/references/cloud/server-nodejs/databases#createCollection

Kenny
18 Mar, 2025, 16:36

You could do something like creating a function that is triggered off the event of a new business document being added into your main business collection.

In this function you would create the new collection for that business and add the initial set of attributes that you want.

You can then have a collection that shows when it's ready so the customer can start operation. And in your UI you have some sort of "Standby, were getting everything ready for you" page.

Rabin Acharya
18 Mar, 2025, 16:38

I am using flutter, is there server side package for flutter?

Kenny
18 Mar, 2025, 16:39

I saw you were using flutter, that's why I mentioned creating a background function that does this.

Kenny
18 Mar, 2025, 16:40

There is a server side package for dart, but I don't know how much help that would be.

Rabin Acharya
18 Mar, 2025, 16:40

sure, brain is being foggy, sorry about that.

Kenny
18 Mar, 2025, 16:41

No biggie :) For these types of operations you wouldn't want to expose it to the client

Rabin Acharya
18 Mar, 2025, 16:41

I got the idea now, thanks:appwriteheart:

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