How to convert existing partition based App to Flexible Sync

Can someone explain the basics required to convert an existing partition based sync to a flexible sync app.

The app needs to always sync all the data in the mode to the clients. Is there any easy way to just sync everything by default or is it necessary to set up some kind of complex query to achieve that.

We have an existing partition based app that is running fine and need to update the schema but it seems we can no longer create a partition based App to test the updated schema because only flexible sync apps can be created now.

So then what are the basic steps required to:

  1. Create a flexible sync App and load the existing data from a local client backup of the sync realm. We usually use a javascript program to do this but if we try and open the target realm as flexible sync then when copying objects to the target we are getting the following error "TypeError, error is not a function.

  2. Assuming we can solve 1) and load the data to the flexible sync App - how would we connect our existing RealmSwift clients to that new App such that all the mode objects are synced.

I have tried reading the MongoDB docs but they are really unhelpful with explaining this relatively simple requirement, nor could I find any examples of flexibleSync setup to sync all database objects to all clients.

Your help will be much appreciated.

EDIT:
It just occurred to be that perhaps I have not opened the flexible sync realm properly. Do I need to set up subscriptions or something in order to be able to write objects to the realm ?

Hi, a few different things to respond to.

First off, Flexible Sync uses “subscriptions” to define which tables and which objects in those tables to subscribe to. I would read this section for your preferred SDK: https://www.mongodb.com/docs/atlas/device-sdks/sdk/swift/sync/flexible-sync/#subscriptions

You can define a subscription on all data for a table, but you do need to specify each table you would like to sync.

As for “not being able to create a partition sync app”. We can re-enable this for you if needed, but we are encouraging people to move development to Flexible Sync as there is much better performance and a lot of new features.

Additionally, we do have an automatic migration for a partition sync app to flexible sync app while in production (though this might not be of interest to you if I understand your situation correctly and that you are in development) https://www.mongodb.com/docs/atlas/app-services/sync/migrate-sync-modes/

To answer your questions about opening a flexible sync app from a backup of the synced realm. Are you trying to open a flexible connection from a partition sync realm? If so, that is not possible at the moment. You will want to just create a new realm and bootstrap down the data from Atlas.

Best,
Tyler

OK so for now I think the best option will be to enable partitioned sync for my account and my clients account. My account is for development/testing and the clients for production.

I have raised a ticket already but if there is any way to expedite enabling partitioned sync on both accounts asap than would be much appreciated.

And then the next thing to do will be to figure out why the load script - that was initially provided by Ian Ward doesn’t seem to be working with flexible sync.

The script just copies the data across - first without any of the Lists (links) and then once all records are copied it recreates the lists and object references by searching for the newly created objects and using the new object references.

To answer your questions about opening a flexible sync app from a backup of the synced realm. Are you trying to open a flexible connection from a partition sync realm? If so, that is not possible at the moment. You will want to just create a new realm and bootstrap down the data from Atlas.

Sorry missed this part.

We use a local backup of the partition synced realm to perform the scheme changes with a local connection and automatic migration to the new schema.

Once this is done we usually load the data using a javascript program which opens the local realm file and opens the new synced realm and then writes the records from the local realm to the synced realm. This works fine with the partitioned synced realm and we have been using it forever (last 5 years or so) - but fails with the flexible sync realm. For some reason it fails when opening the synced realm if we use the initialSubscriptions property. And if we don’t use it we get an exception when trying to write the first object to the synced realm - but you need to create the subscriptions first in order to perform the write.

So presumably we are doing something wrong in the script when opening the flexible synced realm.

Script is attached to the ticket.

Following up that it seems like you have reached out to the support team and they are handling your issue, so we will let that process take over here.