Back

[SOLVED] RealTime subscription

  • 0
  • Databases
  • Realtime
  • Cloud
ROAD 6
11 Dec, 2023, 17:42

Hello I’m new here so hi again 👋 I’m trying to use realtime to check if new content created or content deleted in the db live.

I used : realtime.subscribe {response in print(response.events)} and I don’t understand why it’s events and not event I checked if it’s end with update/create/delete and I’m checking only events.first! I’m missing data with my approach?

TL;DR
User had a RealTime subscription issue but got it solved. They were confused about using events instead of event. They were also unsure if their approach was missing data. The solution was to discard unnecessary events and only focus on the latest event. The code should read the first event and determine the last 6 digits to fire the appropriate method.
D5
11 Dec, 2023, 18:00

It throws an event each time it changes. First request you will need to get data manually like no real-time data. After that, such method will be triggered with the corresponding data

ROAD 6
11 Dec, 2023, 19:46

Thank you for your answer! I have method triggered each time on the first event of the events array it’s working but I’m not pretty sure I did it right so When the subscription is triggered live with delete/update/create… its create array of events for example like that :

ROAD 6
11 Dec, 2023, 20:02

{ "events": [ "databases.default.collections.movies.documents.lion-king.create", "databases..collections..documents..create", "databases.default.collections..documents.lion-king.create", "databases..collections..documents.lion-king.create", "databases..collections.movies.documents.lion-king.create", "databases.default.collections.movies.documents..create", "databases..collections.movies.documents..create", "databases.default.collections..documents..create", "databases.default.collections.movies.documents.lion-king", "databases..collections..documents.", "databases.default.collections..documents.lion-king", "databases..collections..documents.lion-king", "databases..collections.movies.documents.lion-king", "databases.default.collections.movies.documents.", "databases..collections.movies.documents.", "databases.default.collections..documents.", "databases.default.collections.movies", "databases..collections.", "databases.default.collections.", "databases..collections.movies", "databases.default", "databases.*" ] }

ROAD 6
11 Dec, 2023, 20:04

And my code read only the first one events.first and find out what the last 6 digits are and fire the right method for it That’s good or bad?

D5
11 Dec, 2023, 20:42

If you don't need everything it will be better to discard the other events and only get latest

ROAD 6
12 Dec, 2023, 19:37

Got it solved thanks !

D5
12 Dec, 2023, 19:40

[SOLVED] RealTime subscription

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