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

# Changes API: How to Subscribe to Operation Changes

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.java.md), [Node.js](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.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**
>
> Subscribe to operation changes using `ForOperationId` or `ForAllOperations`.
>
> > **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:
>   - [ForOperationId](#foroperationid)
>   - [ForAllOperations](#foralloperations)
>   - [Syntax](#syntax)

## ForOperationId {#foroperationid}

Operation changes for one operation can be observed using the `ForOperationId` method.

> **Note**
>
> Please note that from RavenDB 6.2 on, operation changes can be tracked only on a **specific node**.  
> The purpose of this change is to improve results consistency, as an operation may behave very differently
> on different nodes and cross-cluster tracking of an operation may become confusing and ineffective if
> the operation fails over from one node to another.  
> Tracking operations will therefore be possible only if the `Changes` API was
> [opened](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.md#accessing-changes-api) using a method that limits
> tracking to a single node: `store.Changes(dbName, nodeTag)`

### ForOperationId syntax

```csharp
IChangesObservable<OperationStatusChange> ForOperationId(long operationId);
```

| Parameters | | |
| - | - | - |
| **operationId** | long | ID of an operation for which notifications will be processed. |

| Return Value | |
| - | - |
| IChangesObservable<[OperationStatusChange](#syntax)> | Observable that allows you to add subscriptions to notifications for an operation with a given ID. |

### Example

```csharp
IDisposable subscription = store
    .Changes(dbName, nodeTag)
    .ForOperationId(operationId)
    .Subscribe(
        change =>
        {
            switch (change.State.Status)
            {
                case OperationStatus.InProgress:
                    //Do Something
                    break;
                case OperationStatus.Completed:
                    //Do Something
                    break;
                case OperationStatus.Faulted:
                    //Do Something
                    break;
                case OperationStatus.Canceled:
                    //Do Something
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        });
```

## ForAllOperations {#foralloperations}

Operations changes for all Operations can be observed using the `ForAllOperations` method.

> **Note**
>
> Please note that from RavenDB 6.2 on, operation changes can be tracked only on a **specific node**.  
> The purpose of this change is to improve results consistency, as an operation may behave very differently
> on different nodes and cross-cluster tracking of an operation may become confusing and ineffective if
> the operation fails over from one node to another.  
> Tracking operations will therefore be possible only if the `Changes` API was
> [opened](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.md#accessing-changes-api) using a method that limits
> tracking to a single node: `store.Changes(dbName, nodeTag)`

### ForAllOperations syntax

```csharp
IChangesObservable<OperationStatusChange> ForAllOperations();
```

| Return Value | |
| - | - |
| IChangesObservable<[OperationStatusChange](#syntax)> | Observable that allows to add subscriptions to notifications for all operations. |

### Example

```csharp
IDisposable subscription = store
    .Changes(dbName, nodeTag)
    .ForAllOperations()
    .Subscribe(change => Console.WriteLine("Operation #{1} reports progress: {0}", change.State.Progress.ToJson(), change.OperationId));
```

## Syntax {#syntax}

### OperationStatusChange

**The notification object delivered to subscribers when an operation changes.**

```csharp
class OperationStatusChange
{
    long OperationId
    OperationState State
}
```

| Property | Type | Description |
| - | - | - |
| **OperationId** | long | Operation ID |
| **State** | [OperationState](#syntax) | Operation state |

### OperationState

```csharp
class OperationState
{
    IOperationResult Result
    IOperationProgress Progress
    OperationStatus Status
}
```

| Property | Type | Description |
| - | - | - |
| **Result** | [IOperationResult](#syntax) | Operation result |
| **Progress** | IOperationProgress | Instance of IOperationProgress (json representation of the progress) |
| **Status** | [OperationStatus](#syntax) | Operation status |

### IOperationResult

```csharp
interface IOperationResult
{
    string Message
    bool ShouldPersist
    bool CanMerge
}
```

| Property | Type | Description |
| - | - | - |
| **Message** | string | Operation message |
| **ShouldPersist** | bool | determine whether or not the result should be saved in the storage |
| **CanMerge** | bool | Whether this result can be merged with another operation result |

### OperationStatus

```csharp
enum OperationStatus
{
    InProgress,
    Completed,
    Faulted,
    Canceled,
}
```

| Name | Description |
| - | - |
| **InProgress** | `Indicates that the operation made progress` |
| **Completed** | `Indicates that the operation has completed` |
| **Faulted** | `Indicates that the operation is faulted` |
| **Canceled** | `Indicates that the operation has been Canceled` |

## 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)
