Rank 1: Thread
How to create collection base on an attribute update in documents using node js function? Collection name should be the data from updated attribute.
Votes
0
Replies
18
Participants
Unknown
Messages
19
Rank 1: Thread
How to create collection base on an attribute update in documents using node js function? Collection name should be the data from updated attribute.
Admin
You want to create a collection if a document is updated?
Rank 1: Thread
Yes
Rank 1: Thread
It's a one time setup related function. So two users can use that same collection.
Admin
Sorry I don't understand
Rank 1: Thread
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.
Admin
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?
Admin
Do you really need a collection per room? Why not just a collection of chat messages?
Rank 1: Thread
It's a couple's app each couple have their seperate collection. 1-1 communication
Admin
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
Rank 1: Thread
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?
Admin
As long as you have the permissions on place, there's no concerns with privacy. Pulling data is negligible
Rank 1: Thread
Okay.
Admin
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
Rank 1: Thread
Mixing together all the messages of all users in a single collection doesn't sound good.
Rank 1: Thread
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?
Admin
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
Admin
It's pretty normal
Rank 1: Thread
Okay