---
title: Syncing Data
slug: v4-8/sync/syncing-data
docTags: 
createdAt: 2023-08-22T20:57:32.293Z
---

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

:::hint{type="warning"}
DQL sync subscriptions are supported for devices on version 4.5 or later.&#x20;

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

- To get your active subscriptions, call the `subscriptions` method on the `ditto.sync` namespace. ([Retrieving Subscriptions](./#retrieving-subscriptions))

- To cancel a subscription, call `cancel` on its subscription object you instantiated when setting up your subscription. ([Canceling Subscriptions](./#canceling-subscriptions))

- To confirm cancelation, call the `isCancelled` field on the subscription object. ([Canceling Subscriptions](./#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`:

:::CodeblockTabs
```swift
ditto.sync.registerSubscription("SELECT * FROM cars")
```

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

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

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

```csharp
ditto.Sync.RegisterSubscription("SELECT * FROM cars");
```

```cpp
auto subscription = 
  ditto.sync().register_subscription("SELECT * FROM cars");
```

```rust
let subscription = 
  ditto.sync().register_subscription("SELECT * FROM cars", None);
```

```dart
await ditto.sync.registerSubscription("SELECT * FROM cars");
```
:::

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

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

```kotlin
ditto.sync.registerSubscription("""
  SELECT *
  FROM cars
  WHERE color = :color
  """,
  mapOf("color" to "blue"))
```

```javascript
ditto.sync.registerSubscription(`
  SELECT *
  FROM cars
  WHERE color = :color`,
  { color: 'blue' })
```

```java
ditto.sync.registerSubscription(
  "SELECT * FROM cars WHERE color = :color",
  Collections.singletonMap("color", "blue"))
```

```csharp
var queryArguments = new Dictionary<string, object>(){{"color", "blue" }};

ditto.Sync.RegisterSubscription(
  "SELECT * FROM cars WHERE color = 'blue'",
  queryArguments);
```

```cpp
ditto.sync().register_subscription(
  "SELECT * FROM cars WHERE color = :color",
  {{"color", "blue"}});
```

```rust
struct Args {
  color: String,
}

// ...

let args = Args {
  color: "blue".to_string(),
};
ditto.sync().register_subscription(
  "SELECT * FROM cars WHERE color = :color",
  args);
```

```dart
await ditto.sync.registerSubscription("""
  SELECT *
  FROM cars
  WHERE color = :color""",
  arguments: {"color": "blue"},
);
```
:::

***

# Retrieving Subscriptions

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

:::CodeblockTabs
```swift
let activeSubscriptions = ditto.sync.subscriptions;
```

```kotlin
val activeSubscriptions = ditto.sync.subscriptions
```

```javascript
const activeSubscriptions = ditto.sync.subscriptions
```

```java
DittoSyncSubscription[] activeSubscriptions = ditto.sync.subscriptions;
```

```csharp
var activeSubscriptions = ditto.Sync.Subscriptions;
```

```cpp
// Not Supported. Hold the reference to the SyncSubscription object.
```

```rust
// Not Supported. Hold the reference to the SyncSubscription object.
```

```dart
final activeSubscriptions = ditto.sync.subscriptions;
```
:::

***

# Canceling Subscriptions

To cancel a subscription, call `cancel` on the subscription object you set up to establish your subscription:

:::CodeblockTabs
```swift
subscription.cancel()
```

```kotlin
subscription.close()
```

```javascript
subscription.cancel()
```

```java
subscription.close()
```

```csharp
subscription.Cancel();
```

```cpp
// ...
```

```rust
// ...
```

```dart
await subscription.cancel()
```
:::

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

:::CodeblockTabs
```swift
subscription.isCancelled
```

```kotlin
subscription.isClosed
```

```javascript
subscription.isCancelled
```

```java
subscription.isCancelled
```

```csharp
subscription.IsCancelled
```

```cpp
// ...
```

```rust
// ...
```

```dart
subscription.isCancelled
```
:::

