Back

RealTime Update

  • 0
  • Accounts
  • Web
  • Realtime
QueenB
30 Aug, 2023, 19:36

Trying to execute a function when there is an update in a particular document ,this is my code and for some reason it is not working.

TL;DR
User is experiencing trouble with real-time updates in their code. They were advised to subscribe to channels instead of events. The user made some corrections, but it still didn't work. A suggestion was given to check permissions and make the collection accessible to all users. Additionally, the user was advised to add a print statement to their code to check subscription data. Another user recommended checking if the user has access to the updated document. Event triggers were suggested as an alternative solution. No solution was provided in the thread.
otik
30 Aug, 2023, 19:53

Maybe in this case you could use event triggers

Guille
30 Aug, 2023, 20:00

The subscription never triggers?

Guille
30 Aug, 2023, 20:01

@otik recommendation may be better for what you want, if you give us more details we can help you

Drake
31 Aug, 2023, 02:09

Can you add a print before the if?

Does the user have access to the document you updated?

QueenB
1 Sep, 2023, 10:42

@Guille it is a CRUD application I am building,so when the user makes changes to the document,like an update on the status of a task , I wanted to trigger a real time notification to the user. But the function does not seem to b working

Guille
1 Sep, 2023, 12:55

Follow Steven recommendation, check the document permission, I would suggest you to make the collection accessible to all users while you are working in this stage, then later you can focus on permissions.

After set the permission you should add a print to your code this way:

TypeScript
function realTime(database, collection, document) {
  console.log({database, collection, document}); // check if subscription data is correct
  client.suscribe(`databases.${database}.collections.${collection}.documents`, response => {
    console.log(response); // read response
  });
}
VincentGe
1 Sep, 2023, 22:25

☝️ Yep permissions are important

QueenB
2 Sep, 2023, 22:04

Thank you I will try this

QueenB
2 Sep, 2023, 22:53

I have checked my permissions, the subscription doesn’t work on document update ,I just want to listen to an update in the attribute of a document.

Drake
2 Sep, 2023, 23:06

you're missing a dot after documents

QueenB
3 Sep, 2023, 11:55

Yes I fixed that

QueenB
3 Sep, 2023, 11:55

But it still didn’t work

VincentGe
3 Sep, 2023, 15:33

You need to subscribe to channels: https://appwrite.io/docs/realtime#channels

VincentGe
3 Sep, 2023, 15:33

You're subscribing to events

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