Global function


Can I create a global user defined function, meaning a function not inside a database?
The use case is for example to create a new project, I would like the function to create a database, a collection of users and an index on the emails.


You could create a parent database and store the function there, however I think what you are trying to do will not work.

As far as I know you can’t decide from inside that function in what database that the collection and indexes should be stored. I would just write a script for that in which the script creates the database and immediately creates a key on that database. With that key you can then make a client to create the collections and indexes.

If you throw that script in a serverless function that you can trigger, then it would probably be the closest option to what you want.

I got your points,
Thanks for the quick reply!