Configure Revisions Operation


  • Use ConfigureRevisionsOperation to apply the following revisions configuration to the database:

    • Default configuration - applies to all document collections.
    • Collection-specific configurations - override the default settings for these collections.
    • To apply a configuration for conflict document revisions see configure conflict revisions.
  • The configuration passed to this operation will REPLACE the current revisions configuration in the database.
    To MODIFY existing configuration, fetch the current configuration from the database record first.

  • After applying the configuration,
    revisions are created and purged for a document whenever the document is created, modified, or deleted.

  • To create a revision when there is no configuration defined (or enabled) see: force revision creation

  • By default, the operation will be applied to the default database.
    To operate on a different database see switch operations to different database.

  • In this page:


Replace configuration

  • In this example, we create a new RevisionsConfiguration for the database.
    If revisions configuration already exists in the database - it will be replaced.

// ==============================================================================
// Define default settings that will apply to ALL collections
// Note: this is optional
var defaultRevConfig = new RevisionsCollectionConfiguration()
{
    MinimumRevisionsToKeep = 100,
    MinimumRevisionAgeToKeep = new TimeSpan(days: 7, 0, 0, 0),
    MaximumRevisionsToDeleteUponDocumentUpdate = 15,
    PurgeOnDelete = false,
    Disabled = false
    
    // With this configuration:
    // ------------------------
    // * A revision will be created anytime a document is modified or deleted.
    // * Revisions of a deleted document can be accessed in the Revisions Bin view.
    // * At least 100 of the latest revisions will be kept.
    // * Older revisions will be removed if they exceed 7 days on next revision creation.
    // * A maximum of 15 revisions will be deleted each time a document is updated,
    //   until the defined '# of revisions to keep' limit is reached.
};

// ==============================================================================
// Define a specific configuration for the EMPLOYEES collection
// This will override the default settings 
var employeesRevConfig = new RevisionsCollectionConfiguration()
{
    MinimumRevisionsToKeep = 50,
    MinimumRevisionAgeToKeep = new TimeSpan(hours: 12, minutes: 0, seconds: 0),
    PurgeOnDelete = true,
    Disabled = false
    
    // With this configuration:
    // ------------------------
    // * A revision will be created anytime an Employee document is modified.
    // * When a document is deleted all its revisions will be removed.
    // * At least 50 of the latest revisions will be kept.
    // * Older revisions will be removed if they exceed 12 hours on next revision creation.
};

// ==============================================================================
// Define a specific configuration for the PRODUCTS collection
// This will override the default settings 
var productsRevConfig = new RevisionsCollectionConfiguration()
{
    Disabled = true 
    // No revisions will be created for the Products collection,
    // even though default configuration is enabled
};

// ==============================================================================
// Combine all configurations in the RevisionsConfiguration object
var revisionsConfig = new RevisionsConfiguration()
{
    Default = defaultRevConfig,
    Collections = new Dictionary<string, RevisionsCollectionConfiguration>()
    {
        { "Employees", employeesRevConfig },
        { "Products", productsRevConfig }
    }
};

// ==============================================================================
// Define the configure revisions operation, pass the configuration
var configureRevisionsOp = new ConfigureRevisionsOperation(revisionsConfig);

// Execute the operation by passing it to Maintenance.Send
// Any existing configuration will be replaced with the new configuration passed
documentStore.Maintenance.Send(configureRevisionsOp);
// ==============================================================================
// Define default settings that will apply to ALL collections
// Note: this is optional
var defaultRevConfig = new RevisionsCollectionConfiguration()
{
    MinimumRevisionsToKeep = 100,
    MinimumRevisionAgeToKeep = new TimeSpan(days: 7, 0, 0, 0),
    MaximumRevisionsToDeleteUponDocumentUpdate = 15,
    PurgeOnDelete = false,
    Disabled = false,
    
    // With this configuration:
    // ------------------------
    // * A revision will be created anytime a document is modified or deleted.
    // * Revisions of a deleted document can be accessed in the Revisions Bin view.
    // * At least 100 of the latest revisions will be kept.
    // * Older revisions will be removed if they exceed 7 days on next revision creation.
    // * A maximum of 15 revisions will be deleted each time a document is updated,
    //   until the defined '# of revisions to keep' limit is reached.
};

// ==============================================================================
// Define a specific configuration for the EMPLOYEES collection
// This will override the default settings 
var employeesRevConfig = new RevisionsCollectionConfiguration()
{
    MinimumRevisionsToKeep = 50,
    MinimumRevisionAgeToKeep = new TimeSpan(hours: 12, minutes: 0, seconds: 0),
    PurgeOnDelete = true,
    Disabled = false
   
    // With this configuration:
    // ------------------------
    // * A revision will be created anytime an Employee document is modified.
    // * When a document is deleted all its revisions will be removed.
    // * At least 50 of the latest revisions will be kept.
    // * Older revisions will be removed if they exceed 12 hours on next revision creation.
};
    
// ==============================================================================
// Define a specific configuration for the PRODUCTS collection
// This will override the default settings 
var productsRevConfig = new RevisionsCollectionConfiguration()
{
    Disabled = true 
    // No revisions will be created for the Products collection,
    // even though default configuration is enabled
};

// ==============================================================================
// Combine all configurations in the RevisionsConfiguration object
var revisionsConfig = new RevisionsConfiguration()
{
    Default = defaultRevConfig,
    Collections = new Dictionary<string, RevisionsCollectionConfiguration>()
    {
        { "Employees", employeesRevConfig },
        { "Products", productsRevConfig }
    }
};

// ==============================================================================
// Define the configure revisions operation, pass the configuration
var configureRevisionsOp = new ConfigureRevisionsOperation(revisionsConfig);
               
// Execute the operation by passing it to Maintenance.SendAsync
// Any existing configuration will be replaced with the new configuration passed
await documentStore.Maintenance.SendAsync(configureRevisionsOp);

Modify configuration

  • In this example, we fetch the existing revisions configuration from the database record and modify it.

// ==============================================================================
// Define the get database record operation:
var getDatabaseRecordOp = new GetDatabaseRecordOperation(documentStore.Database);
// Get the current revisions configuration from the database record:
RevisionsConfiguration revisionsConfig =
    documentStore.Maintenance.Server.Send(getDatabaseRecordOp).Revisions;

// ==============================================================================
// If no revisions configuration exists, then create a new configuration
if (revisionsConfig == null)
{
    revisionsConfig = new RevisionsConfiguration()
    {
        Default = defaultRevConfig,
        Collections = new Dictionary<string, RevisionsCollectionConfiguration>()
        {
            { "Employees", employeesRevConfig },
            { "Products", productsRevConfig }
        }
    };
}

// ==============================================================================
// If a revisions configuration already exists, then modify it
else
{
    revisionsConfig.Default = defaultRevConfig;
    revisionsConfig.Collections["Employees"] = employeesRevConfig;
    revisionsConfig.Collections["Products"] = productsRevConfig;
}

// ==============================================================================
// Define the configure revisions operation, pass the configuration
var configureRevisionsOp = new ConfigureRevisionsOperation(revisionsConfig);

// Execute the operation by passing it to Maintenance.Send
// The existing configuration will be updated
documentStore.Maintenance.Send(configureRevisionsOp);
// ==============================================================================
// Define the get database record operation:
var getDatabaseRecordOp = new GetDatabaseRecordOperation(documentStore.Database);
// Get the current revisions configuration from the database record:
RevisionsConfiguration revisionsConfig =
    documentStore.Maintenance.Server.Send(getDatabaseRecordOp).Revisions;

// ==============================================================================
// If no revisions configuration exists, then create a new configuration
if (revisionsConfig == null)
{
    revisionsConfig = new RevisionsConfiguration()
    {
        Default = defaultRevConfig,
        Collections = new Dictionary<string, RevisionsCollectionConfiguration>()
        {
            { "Employees", employeesRevConfig },
            { "Products", productsRevConfig }
        }
    };
}

// ==============================================================================
// If a revisions configuration already exists, then modify it
else
{
    revisionsConfig.Default = defaultRevConfig;
    revisionsConfig.Collections["Employees"] = employeesRevConfig;
    revisionsConfig.Collections["Products"] = productsRevConfig;
}

// ==============================================================================
// Define the configure revisions operation, pass the configuration
var configureRevisionsOp = new ConfigureRevisionsOperation(revisionsConfig);

// Execute the operation by passing it to Maintenance.SendAsync
// The existing configuration will be updated
await documentStore.Maintenance.SendAsync(configureRevisionsOp);

Syntax

public ConfigureRevisionsOperation(RevisionsConfiguration configuration);
Parameter Type Description
configuration RevisionsConfiguration The revisions configuration to apply

public class RevisionsConfiguration
{
    public RevisionsCollectionConfiguration Default;
    public Dictionary<string, RevisionsCollectionConfiguration> Collections;
}
Property Type Description
Default RevisionsCollectionConfiguration Optional default settings that apply to any collection Not specified in Collections.
Collections Dictionary<string, RevisionsCollectionConfiguration> A Dictionary of collection-specific configurations
The keys are the collection names
The values are the corresponding configurations.
Overrides the default settings for the collections defined.

public class RevisionsCollectionConfiguration
{
    public long? MinimumRevisionsToKeep { get; set; }
    public TimeSpan? MinimumRevisionAgeToKeep { get; set; }
    public long? MaximumRevisionsToDeleteUponDocumentUpdate { get; set; }
    public bool PurgeOnDelete { get; set; }
    public bool Disabled { get; set; }
}

Property Type Description
MinimumRevisionsToKeep long
  • This number of revisions will be kept per document.
  • Older revisions exceeding this number will be purged upon the next document modification.
  • Default : null = no limit
MinimumRevisionAgeToKeep TimeSpan
  • Limit the number of revisions kept per document by their age.
  • Revisions that are older than this time will be purged upon the next document modification.
  • Default : null = no age limit
    MaximumRevisionsToDeleteUponDocumentUpdate long
    • The maximum number of revisions to delete upon each document modification.
    • Default : null = no limit,
      all revisions that pend purging will be deleted.
    PurgeOnDelete bool
    • false ( Default ) - Revisions of a deleted document are moved to the Revisions Bin.
    • true - When a document is deleted all its revisions are also deleted.
    Disabled bool
    • false ( Default ) - Revisions will be created and purged according to the configuration.
    • true - No revisions will be created or purged.