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

# Get Revisions

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.md), [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), [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.php.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**:

```php
// Get revisions for document 'orders/1-A'
// Revisions will be ordered by most recent revision first
/** @var array<Order>  $orderRevisions */
$orderRevisions = $session
  ->advanced()
  ->revisions()
  ->getFor(Order::class, id: "orders/1-A", start: 0, pageSize: 10);
```

- **Syntax**:

```php
public function getFor(?string $className, ?string $id, int $start = 0, int $pageSize = 25): array;
```

| Parameters | Type | Description |
| - | - | - |
| **id** | `string` | Document ID for which to retrieve revisions |
| **className** | `string` | The type of the object whose revisions we want to retrieve |
| **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**:

```php
// Get revisions' metadata for document 'orders/1-A'
/** @var array<MetadataAsDictionary> $orderRevisionsMetadata */
$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
$metadata = $orderRevisionsMetadata[0];
$flagsValue = $metadata[DocumentsMetadata::FLAGS];

$this->assertContains("Revision", $flagsValue);
```

- **Syntax**:

```php
public function getMetadataFor(?string $id, int $start = 0, int $pageSize = 25): array;
```

| 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 `getBeforeDate` to retrieve a revision by its **creation time**.

- **Example**:

```php
// Get a revision by its creation time
$revisionFromLastYear = $session
  ->advanced()
  ->revisions()
   // If no revision was created at the specified time,
   // then the first revision that precedes it will be returned
  ->getBeforeDate(Order::class, "orders/1-A", (new DateTime())->sub(new DateInterval("P1Y")));
```

- **Syntax**:

```php
function getBeforeDate(?string $className, ?string $id, DateTime $date): ?object;
```

| Parameter | Type | Description |
| - | - | - |
| **id** | `string` | The ID of the document whose revisions we want to retrieve by creation time |
| **date** | `DateTime` | Revision creation time |
| **className** | `string` | The type of the object whose revisions we want to retrieve |

## Get revisions by change vector

To retrieve a revision or multiple revisions by **change vectors** use `getMetadataFor`,
extract the change vector from the metadata, and `get` the revision using the change vector.

- **Example**:

```php
// Get revisions metadata
/** @var array<MetadataAsDictionary> $revisionsMetadata */
$revisionsMetadata = $session
  ->advanced()
  ->revisions()
  ->getMetadataFor("orders/1-A", start: 0, pageSize: 25);

// Get the change-vector from the metadata
$changeVector = $revisionsMetadata[0][DocumentsMetadata::CHANGE_VECTOR];

// Get the revision by its change-vector
$revision = $session
  ->advanced()
  ->revisions()
  ->get(Order::class, $changeVector);
```

- **Syntax**:

```php
// Get a revision(s) by its change vector(s)
public function get(?string $className, null|string|array|StringArray $changeVectors): mixed;
```

| Parameter | Type | Description |
| - | - | - |
| **changeVectors** | `null` or `string` or `array` or `StringArray` | A list of change vector strings |
| **className** | `className` | The types of the objects whose revisions we want to retrieve |

## 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.php.md)
- [Revisions: API Overview](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/overview.php.md)
- [Operations: Configuring Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/operations/configure-revisions.php.md)
- [Session: Including Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/including.php.md)
- [Session: Counting Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/counting.php.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)
