Using flexible sync check the data before syncing to Realm using react native

I am using realm for offline implementation. I have stuck since one week regarding below issue. If suppose two users update the same record during offline, One of the user gets online and sync the data to the realm server. When the second user gets online his data also sync into the server that means override the first user data instead of checking whether the data changed or not in the realm server. Can any one help here?

Hi, please see this documentation page for our conflict resolution algorithm: https://www.mongodb.com/docs/atlas/app-services/sync/details/conflict-resolution/#custom-conflict-resolution

For simple fields we employ a “last writer wins” policy. If you require custom conflict resolution for some fields, we advise re-thinking the data model. For example:

  1. Instead of primitive field, make it a list and append to the end of it. Device Sync will ensure the list is the same across all devices, and your client-side application can determine which value it wants to present to the user (first or last)
  2. Instead of a primitive field, make it a dictionary keyed on the user that updated the field. Then you can have your client-side logic determine which value should be shown.

Let me know if this solves your issue? If not, please let me know what you would expect to be able to do in the above situation.

Best,
Tyler

Can you give some example snippet?

Do you have more details about what exactly you are trying to do? See here for how to use a dictionary: https://www.mongodb.com/docs/realm/sdk/react-native/model-data/data-types/dictionaries/ and here for how to use a list https://www.mongodb.com/docs/realm/sdk/react-native/model-data/data-types/collections/

Your answers not cleared

Hi, I would love to help out, but can you please provide more information about what is unclear or what exactly you would like to do?

I need to check the collection values before syncing to realm server. I am using react native SDK.

There is no way to check the values specifically before it is synced. You can however pause and un-pause the sync session if you have to do so and capture the information about the pre and post value for the field in question. Additionally, you can use things like listeners to be notified when sync changes the value of a field: https://www.mongodb.com/docs/realm/sdk/react-native/react-to-changes/

Okay Thanks for response, Can you give some code snippet checking the changes with server data during pause and un pause sync?

During offline, when pause the sync and try to reload the app. It’s giving error and crashing the app

Error: no internal field

This error is located at:
in AppSync (created by AppWrapperSync)
in Unknown (created by AppWrapperSync)
in UserProvider (created by AppWrapperSync)
in AuthOperationProvider (created by AppProvider)
in AppProvider (created by AppWrapperSync)
in RCTView (created by View)
in View (created by AppWrapperSync)
in AppWrapperSync (created by App)
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in realApp(RootComponent), js engine: hermes
ERROR [Error: no internal field]