On this page
If you have a mobile app that uses a local realm and you want to convert the app to use Sync, there are a few steps you need to follow. You first need to set up an App backend. Then, make code changes in your client applications.
In the following sections, you will learn to do the following on the backend:
Create a new App in MongoDB Atlas,
Configure at least one authentication provider
Choose a Sync type.
And then, in your client app, you will:
Update your Realm object models,
Connect to the new synced realm with a sync configuration file,
Authenticate the user.
Finally, if needed, you will also need to copy your local data to the new synced realm.
To sync your data between devices and MongoDB Atlas, you first need to create an App. This App provides a gateway to the data and data security in the form of user authentication, data encryption, and access control.
To get started creating the backend app, follow the steps in Create an App with the App Services UI.
Atlas Device Sync requires authenticated users. Atlas App Services provides many different Authentication Providers such as email/password and OAuth; once you have configured one or more providers, you can then control exactly who has access to which data.
To set up an authentication provider, choose one of the providers and follow the configuration steps for the provider(s) of your choice.
There are two Sync Modes: Flexible Sync and the older Partition-Based Sync. We recommend using Flexible Sync.
With Flexible Sync, clients synchronize subsets of data based on queries to queryable fields. When configuring Flexible Sync, you decide which fields clients can query upon. To learn more, follow the steps in Procedure.
Now that you have the backend set up for Device Sync, you need to make a few changes in your client app. Follow the steps in the Quick Start for your language/platform:
Alternate SDK Implementations
Some SDKs support an easier implementation for adding sync to a local-only realm than the steps outlined on this section.
None of the data in your local realm automatically transfers to a new synced realm . You must copy the data you want to preserve to the new realm. The following diagram and steps outline the process for copying all of the data from a local realm to a synced realm.
|||With the exception of apps migrated from local to synced realms using the easier implementations outlined in "Alternate SDK Implementations".|
Check if a synced realm already exists.
If not, create one. Open a connection to it and to the local realm.
Read each record from the local realm and modify it to match the schema of the synced realm.
Copy the modified record to the new synced realm. Sync automatically copies the record to MongoDB Atlas when connected to your App.
Confirm that all records you want to preserve are in the new realm.
Delete the local realm file.
On each subsequent app load, check if the local realm has been deleted.