Revisions: Loading Revisions


You can retrieve revisions and their metadata from the database using these Session methods:

  • session.Advanced.Revisions.GetFor
    Retrieves all the revisions currently kept for a specified document
  • session.Advanced.Revisions.GetMetadataFor
    Retrieves the metadata for all the revisions currently kept for a specified document
  • session.Advanced.Revisions.Get
    Retrieves a revision or multiple revisions by their change vectors
    Retrieves a revision by its creation time

  • In this page:


GetFor

Use GetFor to retrieve all of the revisions currently kept for a specified document.

Syntax

List<T> GetFor<T>(string id, int start = 0, int pageSize = 25);
Parameters
id string ID of the document whose revisions are retrieved
start int First revision to retrieve
pageSize int How many revisions to retrieve per page

Example

List<Order> orderRevisions = session
    .Advanced
    .Revisions
    .GetFor<Order>(
        id: "orders/1-A",
        start: 0,
        pageSize: 10);
List<Order> orderRevisions = await asyncSession
    .Advanced
    .Revisions
    .GetForAsync<Order>(
        id: "orders/1-A",
        start: 0,
        pageSize: 10);

GetMetadataFor

Use GetMetadataFor to retrieve the metadata for all the revisions currently kept for a specified document.

Syntax

List<MetadataAsDictionary> GetMetadataFor(string id, int start = 0, int pageSize = 25);
Parameters
id string ID of the document whose revisions' metadata is retrieved
start int First revision to retrieve metadata for
pageSize int how many revisions to retrieve per page

Example

List<MetadataAsDictionary> orderRevisionsMetadata =
    session
        .Advanced
        .Revisions
        .GetMetadataFor(
            id: "orders/1-A",
            start: 0,
            pageSize: 10);
List<MetadataAsDictionary> orderRevisionsMetadata =
    await asyncSession
        .Advanced
        .Revisions
        .GetMetadataForAsync(
            id: "orders/1-A",
            start: 0,
            pageSize: 10);

Get

Use Get to -

  • Retrieve a revision or multiple revisions by their change vectors
  • Retrieve a revision by its creation time

Syntax

// 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);

// Get a revision by its creation time
// If no revision was created at that precise time, get the first revision to precede it
T Get<T>(string id, DateTime date);
Parameter Type Description
changeVector string a revision's change vectors
changeVectors IEnumerable<string> revisions' change vectors
date DateTime a revision's creation time

Example I

Get a revision by its change vector

Order orderRevision =
    session
        .Advanced
        .Revisions
        // Get revisions by their change vectors
        .Get<Order>(orderRevisionChangeVector);
Order orderRevision =
    await asyncSession
        .Advanced
        .Revisions
        // Get revisions by their change vectors
        .GetAsync<Order>(orderRevisionChangeVector);

Example II

Get the metadata kept for a document's revisions, use it to find a revision's change vector, and retrieve the revision using the change vector.

// Get revisions metadata 
List<MetadataAsDictionary> revisionsMetadata = 
    session
        .Advanced
        .Revisions
        .GetMetadataFor("users/1", start: 0, pageSize: 25);

// Get revision by its change vector
User revison = 
    session
        .Advanced
        .Revisions
        .Get<User>(revisionsMetadata[0].GetString(Constants.Documents.Metadata.ChangeVector));
// Get revisions metadata 
List<MetadataAsDictionary> revisionsMetadata =
    await asyncSession
        .Advanced
        .Revisions
        .GetMetadataForAsync("users/1", start: 0, pageSize: 25);

// Get revision by its change vector
User revison =
    await asyncSession
        .Advanced
        .Revisions
        .GetAsync<User>(revisionsMetadata[0].GetString(Constants.Documents.Metadata.ChangeVector));

Example III

Get a revision by its creation time

User revisonAtYearAgo = 
    session
        .Advanced
        .Revisions
        // Get a revision by its creation time
        .Get<User>("users/1", DateTime.Now.AddYears(-1));
User revisonAtYearAgo =
    await asyncSession
        .Advanced
        .Revisions
        // Get a revision by its creation time
        .GetAsync<User>("users/1", DateTime.Now.AddYears(-1));