Back

Proper event listener for listening to a specific document in a collection? (Realtime)

  • 0
  • Realtime
Snippy
16 Feb, 2023, 16:40

In order to get notifications (per user) I set it up to subscribe to any event taken place in their respective document in a collection. I first subscribe to the collection then listen via "databases..collections..documents". My only issue is that when I change something in the document I am not getting anything printed. The following code :void subscribe() async { final String getId = Boxes.getMainUser().values.first.id; subscription = ApiService.instance!.realTime.subscribe([ 'databases.[637044216b476709d41d].collections.[63704487a16832bfd730].documents.[$getId]' ]); subscription.stream.listen((response) { print("SOmehting happening"); if (response.events.contains('databases.*.collections.*.documents')) { print("SOmehting happening"); } }); }

TL;DR
The user is asking for help with setting up an event listener to listen to a specific document in a collection in real-time. They are not receiving any output when they make changes to the document. They provided their code, which includes subscribing to the collection and listening using the "databases.*.collections.*.documents" channel. They are using the ApiService to set up the subscription. Solution: It is suggested that the user remove the extra brackets around the IDs when subscribing to the document. Additionally, they should check if they are seeing any output in their local console.
joeyouss
16 Feb, 2023, 16:41

Hi there 👋

joeyouss
16 Feb, 2023, 16:44

Are you seeing no output in your local console?

Snippy
16 Feb, 2023, 16:49

Correct, I am not seeing any output in the terminal

Drake
16 Feb, 2023, 20:40

Can you try removing the extra brackets around the IDs

VincentGe
17 Feb, 2023, 18:35

databases.637044216b476709d41d.collections.63704487a16832bfd730.documents

The channel Should be this

Snippy
18 Feb, 2023, 18:44

You guys are live savers!

Snippy
18 Feb, 2023, 18:46

Big help. I don't know if this is an error but when I was using the event listeners in the document it wasn't working so I just printed the response from real-time to see what the actual event key is structured. The docs is structured via databases.*.collections.*.documents.update but the working key is databases.*.collections.*.documents.*.update.

Drake
18 Feb, 2023, 18:50

Channel != Events

Snippy
18 Feb, 2023, 18:55

Correct, I was just meaning it in general.

Drake
18 Feb, 2023, 19:30

Oh sorry I think I see what you mean now. The docs (https://appwrite.io/docs/events#databases-events) say there's an event like ...documents.update but there isn't.

Cc @VincentGe

VincentGe
18 Feb, 2023, 23:07

?>>?????

VincentGe
18 Feb, 2023, 23:07

Wait there is no update event?

VincentGe
18 Feb, 2023, 23:07

LOL

VincentGe
18 Feb, 2023, 23:07

These are auto generated. I will have to dig into this on monday

VincentGe
18 Feb, 2023, 23:07

:sadge

Drake
18 Feb, 2023, 23:13

There should be an ID or wildcard between document and update

VincentGe
18 Feb, 2023, 23:33

Yikes :/

VincentGe
18 Feb, 2023, 23:33

JE see

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