---
title: "Get Revisions"
url: "https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading"
version: "6.2"
language: "csharp"
---

# Get Revisions

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.java.md), [Python](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.python.md), [PHP](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.php.md), [Node.js](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.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**
>
> - Using the Advanced Session methods you can **retrieve revisions and their metadata**  
>   from the database for the specified document.
>
> - These methods can also be executed lazily, see [get revisions lazily](https://docs.ravendb.net/6.2/client-api/session/how-to/perform-operations-lazily.md#getrevisions).
>
> - In this page:
>   - [Get all revisions](#get-all-revisions)
>   - [Get revisions metadata](#get-revisions-metadata)
>   - [Get revisions by creation time](#get-revisions-by-creation-time)
>   - [Get revisions by change vector](#get-revisions-by-change-vector)

## Get all revisions

- Use `GetFor` to retrieve all of the revisions currently kept for the specified document.
  **Example**:

### Sync

```csharp
// Get revisions for document 'orders/1-A'
// Revisions will be ordered by most recent revision first
List<Order> orderRevisions = session
  .Advanced
  .Revisions
  .GetFor<Order>(id: "orders/1-A", start: 0, pageSize: 10);
```

### Async

```csharp
// Get revisions for document 'orders/1-A'
// Revisions will be ordered by most recent revision first
List<Order> orderRevisions = await asyncSession
  .Advanced
  .Revisions
  .GetForAsync<Order>(id: "orders/1-A", start: 0, pageSize: 10);
```

**Syntax**:

```csharp
List<T> GetFor<T>(string id, int start = 0, int pageSize = 25);
```

| Parameters | Type | Description |
| - | - | - |
| **id** | `string` | Document ID for which to retrieve revisions |
| **start** | `int` | First revision to retrieve, used for paging |
| **pageSize** | `int` | Number of revisions to retrieve per results page |

## Get revisions metadata

- Use `GetMetadataFor` to retrieve the metadata for all the revisions currently kept for the specified document.
  **Example**:

### Sync

```csharp
// Get revisions' metadata for document 'orders/1-A'
List<IMetadataDictionary> orderRevisionsMetadata = session
  .Advanced
  .Revisions
  .GetMetadataFor(id: "orders/1-A", start: 0, pageSize: 10);

// Each item returned is a revision's metadata, as can be verified in the @flags key
var metadata = orderRevisionsMetadata[0];
var flagsValue = metadata.GetString(Constants.Documents.Metadata.Flags);

Assert.Contains("Revision", flagsValue);
```

### Async

```csharp
// Get revisions' metadata for document 'orders/1-A'
List<IMetadataDictionary> orderRevisionsMetadata = await asyncSession
  .Advanced
  .Revisions
  .GetMetadataForAsync(id: "orders/1-A", start: 0, pageSize: 10);

// Each item returned is a revision's metadata, as can be verified in the @flags key
var metadata = orderRevisionsMetadata[0];
var flagsValue = metadata.GetString(Constants.Documents.Metadata.Flags);

Assert.Contains("Revision", flagsValue);
```

**Syntax**:

```csharp
List<MetadataAsDictionary> GetMetadataFor(string id, int start = 0, int pageSize = 25);
```

| Parameters | Type | Description |
| - | - | - |
| **id** | `string` | Document ID for which to retrieve revisions' metadata |
| **start** | `int` | First revision to retrieve metadata for, used for paging |
| **pageSize** | `int` | Number of revisions to retrieve per results page |

## Get revisions by creation time

- Use `Get` to retrieve a revision by its **creation time**.
  **Example**:

### Sync

```csharp
// Get a revision by its creation time
Order revisionFromLastYear = session
  .Advanced
  .Revisions
   // If no revision was created at the specified time,
   // then the first revision that precedes it will be returned
  .Get<Order>("orders/1-A", DateTime.Now.AddYears(-1));
```

### Async

```csharp
// Get a revision by its creation time
Order revisionFromLastYear = await asyncSession
  .Advanced
  .Revisions
  // If no revision was created at the specified time,
  // then the first revision that precedes it will be returned
  .GetAsync<Order>("orders/1-A", DateTime.Now.AddYears(-1));
```

**Syntax**:

```csharp
T Get<T>(string id, DateTime date);
```

| Parameter | Type | Description |
| - | - | - |
| **id** | `string` | Document ID for which to retrieve the revision by creation time |
| **date** | `DateTime ` | The revision's creation time |

## Get revisions by change vector

- Use `Get` to retrieve a revision or multiple revisions by their **change vectors**.  
  **Example**:

### Sync

```csharp
// Get revisions metadata 
List<IMetadataDictionary> revisionsMetadata = session
  .Advanced
  .Revisions
  .GetMetadataFor("orders/1-A", start: 0, pageSize: 25);

// Get the change-vector from the metadata
var changeVector = revisionsMetadata[0].GetString(Constants.Documents.Metadata.ChangeVector);

// Get the revision by its change-vector
Order revision = session
  .Advanced
  .Revisions
  .Get<Order>(changeVector);
```

### Async

```csharp
// Get revisions metadata 
List<IMetadataDictionary> revisionsMetadata = await asyncSession
  .Advanced
  .Revisions
  .GetMetadataForAsync("orders/1-A", start: 0, pageSize: 25);

// Get the change-vector from the metadata
var changeVector = revisionsMetadata[0].GetString(Constants.Documents.Metadata.ChangeVector);

// Get the revision by its change-vector
Order revision = await asyncSession
  .Advanced
  .Revisions
  .GetAsync<Order>(changeVector);
```

**Syntax**:

```csharp
// Get a revision by its change vector
T Get<T>(string changeVector);

// Get multiple revisions by their change vectors
Dictionary<string, T> Get<T>(IEnumerable<string> changeVectors);
```

| Parameter | Type | Description |
| - | - | - |
| **changeVector** | `string` | The revision's change vector |
| **changeVectors** | `IEnumerable<string>` | Change vectors of multiple revisions |

## See also

- [Document Revisions Overview](https://docs.ravendb.net/6.2/document-extensions/revisions/overview.md)
- [Revert Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/revert-documents-to-revisions/revert-documents-to-specific-time.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)
- [Operations: Configuring Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/operations/configure-revisions.md)
- [Session: Including Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/including.md)
- [Session: Counting Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/counting.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)
