---
title: "What Is the Changes API"
url: "https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api"
version: "6.2"
language: "csharp"
---

# What Is the Changes API

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.java.md), [Node.js](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - The Changes API is a Push Notifications service, that allows a RavenDB Client to
>   receive messages from a RavenDB Server regarding events that occurred on the server.
> - A client can subscribe to events related to documents, indexes, operations, counters, and time series.
> - Using the Changes API allows you to notify users of various changes without requiring
>   any expensive polling.
>
> > **Warning**
> >
> > The `Subscribe` method on the observables the Changes API returns accepts only an `IObserver`
> > object by default.  
> > To instead subscribe with a delegate, like the `change => ...` lambda used in the examples below,
> > add the [System.Reactive](https://www.nuget.org/packages/System.Reactive/) package to your project.  
> > This adds `Subscribe` overloads that take delegates, including ones with error and
> > completion handlers.
>
> - In this article:
>   - [Accessing Changes API](#accessing-changes-api)
>   - [Connection interface](#connection-interface)
>   - [Subscribing](#subscribing)
>   - [Unsubscribing](#unsubscribing)
>   - [Changes API and Database Timeout](#changes-api-and-database-timeout)
>   - [Changes API -vs- Data Subscriptions](#changes-api-vs-data-subscriptions)

## Accessing Changes API {#accessing-changes-api}

The changes subscription is accessible by a document store through its `IDatabaseChanges`
or `ISingleNodeDatabaseChanges` interfaces.

```csharp
IDatabaseChanges Changes(string database = null);

ISingleNodeDatabaseChanges Changes(string database, string nodeTag);
```

| Parameters | | |
| - | - | - |
| **database** | `string` | Name of database to open changes API for. If `null`, the `Database` configured in DocumentStore will be used. |
| **nodeTag** | `string` | Tag of the cluster node to open changes API for. |

| Return value | |
| - | - |
| `IDatabaseChanges` | Instance implementing `IDatabaseChanges` interface. |
| `ISingleNodeDatabaseChanges` | Instance implementing `ISingleNodeDatabaseChanges` interface. |

- Use `IDatabaseChanges` to subscribe to database changes.
- Use `ISingleNodeDatabaseChanges` to limit tracking to a specific node.
  > **Note**
  >
  > Note that from RavenDB 6.2 on, some changes can be tracked not cross-cluster but only
  > **on a specific node**. In these cases, it is required that you open the Changes API using
  > the second overload, passing both a database name and a node tag: `store.Changes(dbName, nodeTag)`

## Connection interface {#connection-interface}

`IDatabaseChanges` inherits from `IConnectableChanges<TChanges>` interface that represent the connection.

```csharp
public interface IConnectableChanges<TChanges> : IDisposable
    where TChanges : IDatabaseChanges
{
    // returns state of the connection
    bool Connected { get; }

    // A task that ensures that the connection to the server was established.
    Task<TChanges> EnsureConnectedNow();

    //An event handler to detect changed to the connection status
    event EventHandler ConnectionStatusChanged;

    //An action to take if an error occured in the connection to the server
    event Action<Exception> OnError;
}
```

## Subscribing {#subscribing}

To receive notifications regarding server-side events, subscribe using one of the following methods.

- **For Document Changes:**
  - [ForAllDocuments](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md#foralldocuments)  
    Track changes for all document
  - [ForDocument](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md#fordocument)  
    Track changes for a given document (by Doc ID)
  - [ForDocumentsInCollection](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md#fordocumentsincollection)  
    Track changes for all documents in a given collection
  - [ForDocumentsStartingWith](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md#fordocumentsstartingwith)  
    Track changes for documents whose ID contains a given prefix

- **For Index Changes:**
  - [ForAllIndexes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-index-changes.md#forallindexes)  
    Track changes for all indexes
  - [ForIndex](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-index-changes.md#forindex)  
    Track changes for a given index (by Index Name)

- **For Operation Changes:**  
  Operation changes can be tracked only [on a specific node](#accessing-changes-api).
  - [ForAllOperations](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.md#foralloperations)  
    Track changes for all operation
  - [ForOperationId](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.md#foroperationid)  
    Track changes for a given operation (by Operation ID)

- **For Counter Changes:**
  - [ForAllCounters](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-counter-changes.md#forallcounters)  
    Track changes for all counters
  - [ForCounter](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-counter-changes.md#forcounter)  
    Track changes for a given counter (by Counter Name)
  - [ForCounterOfDocument](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-counter-changes.md#forcounterofdocument)  
    Track changes for a specific counter of a chosen document (by Doc ID and Counter Name)
  - [ForCountersOfDocument](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-counter-changes.md#forcountersofdocument)  
    Track changes for all counters of a chosen document (by Doc ID)

- **For Time Series Changes:**
  - [ForAllTimeSeries](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-time-series-changes.md#foralltimeseries)  
    Track changes for all time series
  - [ForTimeSeries](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-time-series-changes.md#fortimeseries)  
    Track changes for all time series with a given name
  - [ForTimeSeriesOfDocument](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-time-series-changes.md#fortimeseriesofdocument)  
    Track changes for -
    - a **specific time series** of a given document (by Doc ID and Time Series Name)
    - **any time series** of a given document (by Doc ID)

## Unsubscribing {#unsubscribing}

To end a subscription (stop listening for particular notifications) you must
`Dispose` of the subscription.

```csharp
IDatabaseChanges changes = store.Changes();
await changes.EnsureConnectedNow();
var subscription = changes
        .ForAllDocuments()
        .Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
try
{
    // application code here
}
finally
{
    if (subscription != null)
        subscription.Dispose();
}
```

## Changes API and Database Timeout {#changes-api-and-database-timeout}

One or more open Changes API connections will prevent a database from becoming
idle and unloaded, regardless of [the configuration value for database idle timeout](https://docs.ravendb.net/6.2/server/configuration/database-configuration.md#databasesmaxidletimeinsec).

## Changes API -vs- Data Subscriptions {#changes-api-vs-data-subscriptions}

**Changes API** and [Data Subscription](https://docs.ravendb.net/6.2/client-api/data-subscriptions/what-are-data-subscriptions.md)
are services that a RavenDB Server provides subscribing clients.  
Both services respond to events that take place on the server, by sending updates
to their subscribers.

- **Changes API is a Push Notifications Service**.
  - Changes API subscribers receive **notifications** regarding events that
    took place on the server, without receiving the actual data entities
    affected by these events.  
    For the modification of a document, for example, the client will receive
    a [DocumentChange](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md#documentchange-and-documentchangetypes-syntax)
    object with details like the document's ID and collection name.

  - The server does **not** keep track of sent notifications or
    checks clients' usage of them. It is a client's responsibility
    to manage its reactions to such notifications.

- **Data Subscription is a Data Consumption Service**.
  - A Data Subscription task keeps track of document modifications in the
    database and delivers the documents in an orderly fashion when subscribers
    indicate they are ready to receive them.
  - The process is fully managed by the server, leaving very little for
    the subscribers to do besides consuming the delivered documents.

| | Data Subscriptions | Changes API |
| - | - | - |
| What can the server Track | [Documents](https://docs.ravendb.net/6.2/client-api/data-subscriptions/what-are-data-subscriptions.md#documents-processing) <br /> [Revisions](https://docs.ravendb.net/6.2/client-api/data-subscriptions/advanced-topics/subscription-with-revisioning.md) <br /> [Counters](https://docs.ravendb.net/6.2/client-api/data-subscriptions/creation/examples.md#including-counters) <br /> Time Series | [Documents](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md) <br /> [Indexes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-index-changes.md) <br /> [Operations](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.md) <br /> [Counters](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-counter-changes.md) <br /> [Time Series](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-time-series-changes.md) |
| What can the server Deliver | Documents <br /> Revisions <br /> Counters <br /> Time Series | Notifications |
| Management | Managed by the Server | Managed by the Client |

## See also

- [How to Subscribe to Document Changes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-document-changes.md)
- [How to Subscribe to Index Changes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-index-changes.md)
- [How to Subscribe to Operation Changes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.md)
- [How to Subscribe to Counter Changes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-counter-changes.md)
- [How to Subscribe to Time Series Changes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-time-series-changes.md)
- [How to Subscribe to Document Changes](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.md)
- [What Are Data Subscriptions](https://docs.ravendb.net/6.2/client-api/data-subscriptions/what-are-data-subscriptions.md)
