This article provides instructions on how to create, retrieve, and cancel sync subscriptions:

DQL sync subscriptions are supported for devices on version 4.5 or later.

Devices on Ditto versions 4.4 or earlier are supported, however, they do not sync data through DQL subscriptions.

  • To get your active subscriptions, call the subscriptions method on the ditto.sync namespace. (Retrieving Subscriptions)

  • To cancel a subscription, call cancel on its subscription object you instantiated when setting up your subscription. (Canceling Subscriptions)

  • To confirm cancelation, call the isCancelled field on the subscription object. (Canceling Subscriptions)


Creating Subscriptions

To register a new sync subscription in your app. For example, the following snippet demonstrates how to establish a subscription to sync updates to documents in the cars collection with a field of color set to the value blue:


ditto.sync.registerSubscription("SELECT * FROM cars")

Sync subscriptions also support argument injection using the :argument syntax in DQL:


ditto.sync.registerSubscription("""
  SELECT *
  FROM cars
  WHERE color = :color
  """,
  [ "color": "blue" ])

Retrieving Subscriptions

Retrieve active sync subscriptions by calling the subscriptions method on the ditto.sync namespace:


let activeSubscriptions = ditto.sync.subscriptions;

Canceling Subscriptions


subscription.cancel()

Check if a sync subscription is canceled by using the isCancelled field on the subscription object:


subscription.isCancelled