Data Sync
This article provides step-by-step instructions for setting up, maintaining, and ending data subscriptions for peer-to-peer asynchronous replication:
To set up a replication subscription in your app:
Syncing large documents can significantly impact sync performance:
Be cautious handling very large binary data, a deeply embedded document, or a very large document. Carefully consider using attachments instead of storing the data directly within a document object. For more information, see Attachment and Large Binary Files.
Start data replication within your app's development lifecycle. (Initiating Replication)
Instantiate a top-level subscription object. (Creating Subscriptions)
If applicable, end the subscription. (Canceling Subscriptions)
To initiate replication, early in your app lifecycle, such as within AppDelegate.application(_:didFinishLaunchingWithOptions:) or Application.onCreate methods, call the startSync method.
You only need to call the following function once.
You must start replication (startSync) in the top-most scope to ensure that as soon as your app starts, it automatically connects with the mesh network and remains active throughout your app's lifecycle.
Otherwise, the peer-to-peer connection may fail, resulting in remote peers becoming unable to send you updates in realtime.
For example, the following snippet demonstrates how to establish a carsSubscription to listen for all updates to documents in the "cars" collection with a field of color set to the value "blue":
For example, continuing with the previous example, the following snippet illustrates canceling the carsSubscription: