Realm Sync automatically synchronizes data between client applications and a MongoDB Realm backend application. When a client device is online, Sync asynchronously synchronizes data in a background thread between the device and your backend Realm app.
When you use Sync in your client application, your implementation must match the Sync Mode you select in your backend Realm app configuration. The Sync Mode options are:
- Partition-Based Sync
- Flexible Sync
You can only use one Sync Mode for your application. You cannot mix Partition-Based Sync and Flexible Sync within the same Realm app.
When you select Partition-Based Sync for your backend Realm app configuration, your client implementation must include a partition value. This is the value of the partition key field you select when you configure Partition-Based Sync.
The partition value determines which data the client application can access.
You pass in the partition value when you open a synced realm.
When you select Flexible Sync for your backend Realm app configuration, your client implementation must include subscriptions to queries on queryable fields. Flexible Sync works by synchronizing data that matches query subscriptions you maintain in the client application.
A subscription set contains a set of queries. Realm Flexible Sync returns documents matching those queries, where the user has the appropriate permissions to read and/or read and write the documents. If documents match the query, but the client does not have the permission to read or write them, they do not sync to the client application.
You can form queries using Realm Query Language.
Flexible Sync does not support all the operators available in Realm Query Language. See Flexible Sync RQL Limitations for details.
Subscription sets are based on a specific type of realm object. You might have multiple subscriptions if you have many types of realm objects.
To use Flexible Sync in your client application, open a synced realm with a flexible sync configuration. Then, manage subscriptions to determine which documents to sync.