How to create collection base on an attribute update in documents using node js function? Collection name should be the data from updated attribute.
You want to create a collection if a document is updated?
Yes
It's a one time setup related function. So two users can use that same collection.
Sorry I don't understand
There is an attribute in User databse called roomName in my project. When two users connect I want that roomName to be their own collection. Where all the chat documents are inside that collection.
In general, you can have a function execute on an event like document update. The document would be in the event function variable. What part are you stuck on exactly?
Do you really need a collection per room? Why not just a collection of chat messages?
It's a couple's app each couple have their seperate collection. 1-1 communication
Again, why? You can use a team and document level permissions to restrict access so only the 2 in the team can read those chat messages
If I keep all the chat messages in one collection for all the users? Won't that cause privacy concerns and longer to pull data from server with real-time and queries?
As long as you have the permissions on place, there's no concerns with privacy. Pulling data is negligible
Okay.
Up to you. It typically makes the most sense to have a collection per data type. If you have multiple collections with the same attribute, you should have a good reason to do so
Mixing together all the messages of all users in a single collection doesn't sound good.
On the function part, are there any examples of events based trigger on demo in Node.js GitHub? And how to get that attribute name in the payload?
You should just deploy a function to see how it works. The document that was updated would be in the APPWRITE_FUNCTION_EVENT_DATA
variable. See https://appwrite.io/docs/functions#functionVariables
It's pretty normal
Okay
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...