---
title: "Revert Documents to Specific Revisions"
url: "https://docs.ravendb.net/6.2/document-extensions/revisions/revert-documents-to-revisions/revert-documents-to-specific-revisions"
version: "6.2"
language: "csharp"
---

# Revert Documents to Specific Revisions

> 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**
>
> - This article describes how to revert specific documents to **specific revisions**.  
>   To revert documents from all collections (or from selected collections) to a **specific point in time**,  
>   see [Revert documents to specific time](https://docs.ravendb.net/6.2/document-extensions/revisions/revert-documents-to-revisions/revert-documents-to-specific-time.md).
>
> - In this article:
>   - [Overview](#overview)
>   - [Revert documents](#revert-documents)
>     - [Revert single document](#revert-single-document)
>     - [Revert multiple documents](#revert-multiple-documents)
>   - [Syntax](#syntax)

## Overview {#overview}

- When reverting to a specific revision,
  the document content will be overwritten by the content of the specified revision.

- Reverting a document to a specific revision can be executed even if the revisions configuration is disabled:
  - **When revisions are ENABLED**:  
    Reverting the document creates a new revision containing the content of the target revision.
  - **When revisions are DISABLED**:  
    The document is reverted to the target revision without creating a new revision.

- In addition to the document itself, reverting will impact *Document Extensions* as follows:
  - **Attachments**:  
    If the target revision owns attachments, they are restored to their state when the revision was created.
  - **Counters**:  
    If the target revision owns counters, they are restored to functionality with their values at the time the revision was created.
  - **Time series**:  
    Time series data is Not reverted. Learn more in [Revisions and time series](https://docs.ravendb.net/6.2/document-extensions/revisions/revisions-and-other-features.md#reverted-data-1).

## Revert documents {#revert-documents}

- You can revert single or multiple documents to specific revisions using the `RevertRevisionsByIdOperation` operation.

- By default, the operation will be applied to the [default database](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.md).  
  To operate on a different database, see [switch operations to different database](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.md).

- To revert a document to a specific revision, provide the document ID and the change-vector of the target revision to the `RevertRevisionsByIdOperation` operation.  
  The document content will be overwritten by the content of the specified revision.

- An exception will be thrown if the revision's change-vector is not found, does not exist for the specified document, or belongs to a different document.

- When executing this operation on a document that had revisions and was deleted, placing it in the Revisions Bin,  
  the document will be **recreated** with the content of the specified target revision and will be removed from the Revisions Bin.

---

### How to obtain a revision's change-vector:

The change-vector of a revision can be obtained via:

- The Client API - follow the code in the examples [below](#revert-single-document)
- Or from the document view in the Studio

![Get revision CV](https://docs.ravendb.net/assets/images/get-cv-for-revision-5604d2dad04a04e3ef477924a2271b1e.png)

1. Go to the Revisions tab in the document view.
2. Click a revision to view
3. The document view will display the content of the revision.  
   This top label indicates that you are viewing a revision and not the current document.
4. Click the copy button in the Properties pane to copy this revision's change-vector to your clipboard.

## Revert single document {#revert-single-document}

Using RavenDB's sample data, document *orders/1-A* has a total of 7 revisions.  
In this example, we revert document *orders/1-A* to its very first revision.

### Sync

```csharp
using (var session = store.OpenSession())
{
    // Get the revisions metadata for the document you wish to revert
    // ==============================================================
    
    var revisionsMetadata = session.Advanced.Revisions
        .GetMetadataFor(id: "orders/1-A");

    // Get the change-vector of the revision you wish to revert to:
    // ============================================================
    
    // Note: revisionsMetadata[0] is the latest revision,
    // so specify the index of the revision you want.
    // In this example, it will be the very first revision of the document:
    
    var numberOfRevisions = revisionsMetadata.Count();
    var revisionChangeVector = revisionsMetadata[numberOfRevisions-1]
        .GetString(Constants.Documents.Metadata.ChangeVector);

    // Execute the operation
    store.Operations.Send(
        // Pass the document ID and the change-vector of the revision to revert to
        new RevertRevisionsByIdOperation("orders/1-A", revisionChangeVector));
}
```

### Async

```csharp
using (var asyncSession = store.OpenAsyncSession())
{
    // Get the revisions metadata for the document you wish to revert
    // ==============================================================
    
    var revisionsMetadata = await asyncSession.Advanced.Revisions
        .GetMetadataForAsync(id: "Orders/1-A");
    
    // Get the change-vector of the revision you wish to revert to:
    // ============================================================
    
    // Note: revisionsMetadata[0] is the latest revision,
    // so specify the index of the revision you want.
    // In this example, it will be the very first revision of the document:
    
    var numberOfRevisions = revisionsMetadata.Count();
    var revisionChangeVector = revisionsMetadata[numberOfRevisions-1]
        .GetString(Constants.Documents.Metadata.ChangeVector);

    // Execute the operation
    await store.Operations.SendAsync(
        // Pass the document ID and the change-vector of the revision to revert to
        new RevertRevisionsByIdOperation("Orders/1-A", revisionChangeVector));
}
```

## Revert multiple documents {#revert-multiple-documents}

You can use the operation to revert multiple documents.  
Note: The documents do not need to belong to the same collection.

### Sync

```csharp
using (var session = store.OpenSession())
{
    // Get the revisions metadata for the documents you wish to revert
    var revisionsMetadata1 = session.Advanced.Revisions
        .GetMetadataFor(id: "orders/1-A");
    var revisionsMetadata2 = session.Advanced.Revisions
        .GetMetadataFor(id: "users/999");

    // Get the change-vector of the revisions you wish to revert to
    var changeVector1 = revisionsMetadata1[2]
        .GetString(Constants.Documents.Metadata.ChangeVector);
    var changeVector2 = revisionsMetadata1[3]
        .GetString(Constants.Documents.Metadata.ChangeVector);

    // Execute the operation
    store.Operations.Send(
        // Pass the document IDs and the change-vector of the revisions to revert to
        new RevertRevisionsByIdOperation(new Dictionary<string, string>()
            { { "orders/1-A", changeVector1 }, { "users/999", changeVector2 } }));
}
```

### Async

```csharp
using (var asyncSession = store.OpenAsyncSession())
{
    // Get the revisions metadata for the documents you wish to revert
    var revisionsMetadata1 = await asyncSession.Advanced.Revisions
        .GetMetadataForAsync(id: "orders/1-A");
    var revisionsMetadata2 = await asyncSession.Advanced.Revisions
        .GetMetadataForAsync(id: "users/999");

    // Get the change-vector of the revisions you wish to revert to
    var changeVector1 = revisionsMetadata1[2]
        .GetString(Constants.Documents.Metadata.ChangeVector);
    var changeVector2 = revisionsMetadata1[3]
        .GetString(Constants.Documents.Metadata.ChangeVector);

    // Execute the operation
    await store.Operations.SendAsync(
        // Pass the document IDs and the change-vector of the revisions to revert to
        new RevertRevisionsByIdOperation(new Dictionary<string, string>()
            { { "orders/1-A", changeVector1 }, { "users/999", changeVector2 } }));
}
```

## Syntax {#syntax}

### `RevertRevisionsByIdOperation`

```csharp
Available overloads:
====================
public RevertRevisionsByIdOperation(string id, string cv);
public RevertRevisionsByIdOperation(Dictionary<string, string> idToChangeVector);
```

| Parameter | Type | Description |
| - | - | - |
| **id** | `string` | The ID of the document to revert. |
| **cv** | `string` | The change-vector of the revision to which the document should be reverted. |
| **idToChangeVector** | `Dictionary<string, string>` | A dictionary where each key is a document ID, and each value is the change-vector of the revision to which the document should be reverted. |

## See also

- [Revisions Overview](https://docs.ravendb.net/6.2/document-extensions/revisions/overview.md)
- [Revert Documents to Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/revert-documents-to-revisions/revert-documents-to-specific-revisions.md)
- [Revisions and Other Features](https://docs.ravendb.net/6.2/document-extensions/revisions/revisions-and-other-features.md)
- [Revisions: API Overview](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/overview.md)
- [What Are Operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.md)
- [Switch Operation Database](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.md)
- [Setting Up a Default Database](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.md)
- [Settings: Document Revisions](https://docs.ravendb.net/6.2/studio/database/settings/document-revisions.md)
- [Document Extensions: Revisions](https://docs.ravendb.net/6.2/studio/database/settings/document-revisions.md)
