Skip to main content

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.
// * Only the latest 100 revisions will be kept. Older ones will be discarded.
// * 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);

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

Syntax

public ConfigureRevisionsOperation(RevisionsConfiguration configuration);
ParameterTypeDescription
configurationRevisionsConfigurationThe revisions configuration to apply
public class RevisionsConfiguration
{
public RevisionsCollectionConfiguration Default;
public Dictionary<string, RevisionsCollectionConfiguration> Collections;
}
PropertyTypeDescription
DefaultRevisionsCollectionConfigurationOptional default settings that apply to any collection Not specified in Collections.
CollectionsDictionary<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; }
}
PropertyTypeDescription
MinimumRevisionsToKeeplong<ul><li>This number of revisions will be kept per document.</li><li>Older revisions exceeding this number will be purged upon the next document modification.<li> Default : null = no limit </li></ul>
MinimumRevisionAgeToKeepTimeSpan<ul><li>Limit the number of revisions kept per document by their age.</li><li>Revisions that are older than this time will be purged upon the next document modification.</li><li> Default : null = no age limit</li><ul>
MaximumRevisionsToDeleteUponDocumentUpdatelong<ul><li>The maximum number of revisions to delete upon each document modification.</li><li> Default : null = no limit,
all revisions that pend purging will be deleted.</li></ul>
PurgeOnDeletebool<ul><li>false ( Default ) - Revisions of a deleted document are moved to the Revisions Bin.</li><li>true - When a document is deleted all its revisions are also deleted.</li></ul>
Disabledbool<ul><li>false ( Default ) - Revisions will be created and purged according to the configuration.</li><li>true - No revisions will be created or purged.</li></ul>