Move from local to synced and back for flexible sync

Hi there,
I need the ability for a customer to have the realm local only. Then subscribe and sync into the cloud. If not required anymore the Customer can go local again and unsubscribe from the sync. The sync method is flexible sync. How can it be archived? Does anyone have any experience with this procedure?

Thank’s in advanced

Hi @Bruno_Zimmermann unfortunately there is no automated way to do what you are trying to do with flexible sync, and your best option would be to do the conversion yourself, moving objects from one realm to another.

That said, we have opened an issue on Github (Add support for realm sync disconnected configuration type · Issue #3110 · realm/realm-dotnet · GitHub) that you can follow and that could help in your case when implemented. The main idea there is to provide a configuration (“disconnected”) that allows to open synced realm without synchronisation.
In that case your flow would be:

  • Open the sync realm the first time with the flexible sync configuration, and let the user log in, then close it.
  • Open the realm with the new “disconnected” config and let the user work offline
  • When the use registers you can open it again with the flexible sync configuration.
  • If needed, you can go back to using the “disconnected” config.

There are two issues with this approach though:

  1. This is not yet implemented
  2. Having a synced realm offline for a long time means that the realm file could greatly grow in size. An offline synced realm is still writing down the “history” of everything that is happening to the objects (so that it can be synced up when online again). This history could become quite big if the user doesn’t go online soon.

For those reason I still think that doing it manually is still the best option in your case.