---
title: "Changes API: How to Subscribe to Time Series Changes"
url: "https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-time-series-changes"
version: "6.2"
language: "csharp"
---

# Changes API: How to Subscribe to Time Series Changes

> Client language: C#.
>
> 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**
>
> - Use the following methods to subscribe to Time Series Changes:
>   - `ForTimeSeries`  
>     Track **all** time series with a given name
>   - `ForTimeSeriesOfDocument`  
>     Overload #1: Track **a specific** time series of a chosen document  
>     Overload #2: Track **any** time series of a chosen document
>   - `ForAllTimeSeries`  
>     Track **all** time series
>
> > **Warning**
> >
> > The `Subscribe` method on the observable these methods return 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:
>   - [ForTimeSeries](#fortimeseries)
>   - [ForTimeSeriesOfDocument](#fortimeseriesofdocument)
>   - [ForAllTimeSeries](#foralltimeseries)
>   - [TimeSeriesChange and TimeSeriesChangeTypes syntax](#timeserieschange-and-timeserieschangetypes-syntax)

## ForTimeSeries {#fortimeseries}

Subscribe to changes in **all time series with a given name**, no matter which document they belong to,
using the `ForTimeSeries` method.

### Syntax

```csharp
IChangesObservable<TimeSeriesChange> ForTimeSeries(string timeSeriesName);
```

| Parameters | | |
| - | - | - |
| **timeSeriesName** | string | Name of a time series to subscribe to. |

| Return Value | |
| - | - |
| IChangesObservable<[TimeSeriesChange](#timeserieschange-and-timeserieschangetypes-syntax)> | Observable that allows to add subscriptions to time series notifications. |

### Example

```csharp
IDisposable subscription = store
    .Changes()
    .ForTimeSeries("Likes")
    .Subscribe
        (change =>
        {
            switch (change.Type)
            {
                case TimeSeriesChangeTypes.Delete:
                    // do something
                break;
            }
        });
```

## ForTimeSeriesOfDocument {#fortimeseriesofdocument}

Use `ForTimeSeriesOfDocument` to subscribe to changes in **time series of a chosen document**.

- Two overload methods allow you to
  - Track **a specific** time series of the chosen document
  - Track **any** time series of the chosen document

### Overload #1

Use this `ForTimeSeriesOfDocument` overload to track changes in a **specific time series** of the chosen document.

#### Syntax

```csharp
IChangesObservable<TimeSeriesChange> ForTimeSeriesOfDocument(string documentId, string timeSeriesName);
```

| Parameters | | |
| - | - | - |
| **documentId** | string | ID of a document to subscribe to. |
| **timeSeriesName** | string | Name of a time series to subscribe to. |

| Return Value | |
| - | - |
| IChangesObservable<[TimeSeriesChange](#timeserieschange-and-timeserieschangetypes-syntax)> | Observable that allows to add subscriptions to time series notifications. |

#### Example

```csharp
IDisposable subscription = store
    .Changes()
    .ForTimeSeriesOfDocument("companies/1-A", "Likes")
    .Subscribe
        (change =>
        {
            switch (change.Type)
            {
                case TimeSeriesChangeTypes.Delete:
                    // do something
                break;
            }
        });
```

### Overload #2

Use this `ForTimeSeriesOfDocument` overload to track changes in **any time series** of the chosen document.

#### Syntax

```csharp
IChangesObservable<TimeSeriesChange> ForTimeSeriesOfDocument(string documentId);
```

| Parameters | | |
| - | - | - |
| **documentId** | string | ID of a document to subscribe to. |

| Return Value | |
| - | - |
| IChangesObservable<[TimeSeriesChange](#timeserieschange-and-timeserieschangetypes-syntax)> | Observable that allows to add subscriptions to time series notifications. |

#### Example

```csharp
IDisposable subscription = store
    .Changes()
    .ForTimeSeriesOfDocument("companies/1-A")
    .Subscribe
        (change =>
        {
            switch (change.Type)
            {
                case TimeSeriesChangeTypes.Delete:
                    // do something
                break;
            }
        });
```

## ForAllTimeSeries {#foralltimeseries}

Subscribe to changes in **all time series** using the `ForAllTimeSeries` method.

### Syntax

```csharp
IChangesObservable<TimeSeriesChange> ForAllTimeSeries();
```

| Return Value | |
| - | - |
| IChangesObservable<[TimeSeriesChange](#timeserieschange-and-timeserieschangetypes-syntax)> | Observable that allows to add subscriptions to time series notifications. |

### Example

```csharp
IDisposable subscription = store
    .Changes()
    .ForAllTimeSeries()
    .Subscribe
        (change =>
        {
            switch (change.Type)
            {
                case TimeSeriesChangeTypes.Delete:
                    // do something
                break;
            }
        });
```

## TimeSeriesChange and TimeSeriesChangeTypes syntax {#timeserieschange-and-timeserieschangetypes-syntax}

### TimeSeriesChange

**The notification object delivered to subscribers when a time series changes.**

```csharp
class TimeSeriesChange
{
    TimeSeriesChangeTypes Type
    string Name
    string DocumentId
    string CollectionName
    DateTime From
    DateTime To
    string ChangeVector
}
```

| Property | Type | Description |
| - | - | - |
| **Type** | [TimeSeriesChangeTypes](#timeserieschange-and-timeserieschangetypes-syntax) | Time series change type enum |
| **Name** | string | Time Series Name |
| **DocumentId** | string | Time series Document Identifier |
| **CollectionName** | string | Time series document Collection Name |
| **From** | DateTime | Time series values From date |
| **To** | DateTime | Time series values To date |
| **ChangeVector** | string | Time series Change Vector |

### TimeSeriesChangeTypes

```csharp
enum TimeSeriesChangeTypes
{
    None,
    Put,
    Delete,
    Mixed,
}
```

| Name | Value |
| - | - |
| **None** | `0` |
| **Put** | `1` |
| **Delete** | `2` |
| **Mixed** | `3` |

## See also

- [What is Changes API](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.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)
