Starting a realm connection replays every change on the server


#1

Is it true that when you initiate a realm connection you will receive all changes made?

I am creating a node app to move files using change events. We use a Realm server to handle the database of where the files are. But since the realm server har been running for some time, records that were there before have now been deleted.

But when i start the node app and get the data from Realm, i get a history of records. It refers to records that have been deleted, and not the “now” state of the realm.

The app then tries to handle the changes that arrive from changeEvent. Since the records are deleted so are the files and the app crashes.


#2

@Drivez Our new query based APIs download the most recent state instead of playing back the history as shown here:
https://docs.realm.io/platform/using-synced-realms/opening-a-synced-realm#partial-synchronization

If you are using our Global Notifier, this API:
https://docs.realm.io/platform/using-synced-realms/server-side-usage/data-change-events

Then yes - it will deliver all everything that has changed in the Realm you are observing - because that is what it is designed to do - be a backend server-side process that allow you create an Event Based framework and react to state changes. Typically, your server-side process would always be running and would be on the same network as ROS so it would never be offline. The changeRealm delivered to you should have insertions ordered by time so if you wanted to only react to the most recent change you could go to the last index in the changeRealm.insertions[x]

Knowing the above you should be able to architect your app in a way that either handles deleted records (by doing a lookup and skipping) or use a different API that only delivers the current state, or by adding a timestamp to your records to infer order.

I hope this helps.


#3

@ianward Thanks, i ended up doing validation as you mention. To check if the object had been handled before.