Operations: How to Configure Revisions
-
Revisions are snapshots of documents that are taken automatically each time a document is updated or deleted.
-
Revisions can be stored indefinitely, or they can be deleted when certain conditions are met. These conditions can be set using the Configure Revisions Operation.
-
In this page:
Syntax
The ConfigureRevisionsOperation modifies the revisions settings for a particular database. Within that database, each collection can have its own separate revisions settings.
To configure the revisions settings for a database and/or the collections in that database, follow these steps:
1. Create a
RevisionsCollectionConfiguration
object for each desired collection.
2. Put those
RevisionsCollectionConfiguration
objects in a RevisionsConfiguration
object.
3. Send that
RevisionsConfiguration
to the server.
RevisionsCollectionConfiguration
This object contains the four revisions settings for a particular collection:
public class RevisionsCollectionConfiguration
{
public TimeSpan? MinimumRevisionAgeToKeep;
public long? MinimumRevisionsToKeep;
public bool Disabled;
public bool PurgeOnDelete;
}
Configuration Option | Description | Default |
---|---|---|
MinimumRevisionsToKeep | The minimum number of revisions to keep per document | null - unlimited |
MinimumRevisionAgeToKeep | The minimum amount of time to keep each revision. Format of TimeSpan . |
null - unlimited |
Disabled | Indicates whether to completely disable revisions for documents in this collection | false |
PurgeOnDelete | When a document is deleted, this indicates whether all of its revisions should be deleted as well | false |
A revision is only deleted if both the MinimumRevisionsToKeep
for that document is exceeded, and the revision is older
than the MinimumRevisionAgeToKeep
limit. The oldest revisions are deleted first.
-
By default both these options are set to
null
, meaning that an unlimited number of revisions will be saved indefinitely. -
If only
MinimumRevisionsToKeep
is null, revisions will be deleted only when they are older thanMinimumRevisionAgeToKeep
. -
If only
MinimumRevisionAgeToKeep
is null, revisions will be deleted each time there are more revisions thanMinimumRevisionsToKeep
.
These deletions will only take place when a new revision is added to a document. Until a new revision is added, that document's revisions can exceed these limits.
RevisionsConfiguration
This object contains a Dictionary
of the revision settings for each collection in the database, plus an optional default
configuration.
public class RevisionsConfiguration
{
public Dictionary<string, RevisionsCollectionConfiguration> Collections;
public RevisionsCollectionConfiguration Default;
}
Property | Description | Default |
---|---|---|
Collections | A dictionary in which the keys are collection names, and the values are the corresponding configurations | null |
Default | An optional default configuration that applies to any collection not listed in Collections |
null |
Note that when this object is sent to the server, it overrides the configurations for all collections, including all existing
configurations currently on the server. If a collection is not listed in Collections
and Default
has not been set, the
default values listed in the table above
are applied.
ConfigureRevisionsOperation
Lastly, the operation itself sends the RevisionsConfiguration
to the server, overriding all existing collection configurations.
You'll want to store these configurations on the client side so they don't have to be created from scratch each time you want to
modify them.
public ConfigureRevisionsOperation(RevisionsConfiguration configuration);
Parameter | Description |
---|---|
configuration | The new revision settings for a particular database |
Example
The following code sample updates the settings of the Document Store's default database
- which in this case is a database named "Northwind". To update the configuration of different database, use the
ForDatabase()
method.
// Create a configuration for the Employees collection
var employeesRevConfig = new RevisionsCollectionConfiguration()
{
MinimumRevisionAgeToKeep = new TimeSpan(hours: 1, minutes: 23, seconds: 45),
MinimumRevisionsToKeep = 42,
PurgeOnDelete = true
};
// Create a configuration for the Products collection
var productsRevConfig = new RevisionsCollectionConfiguration()
{
Disabled = true
};
// Create a default collection configuration
var defaultRevConfig = new RevisionsCollectionConfiguration()
{
MinimumRevisionAgeToKeep = new TimeSpan(days: 7, 0, 0, 0),
MinimumRevisionsToKeep = 100,
PurgeOnDelete = false
};
// Combine to create a configuration for the database
var northwindRevConfig = new RevisionsConfiguration()
{
Collections = new Dictionary<string, RevisionsCollectionConfiguration>()
{
{ "Employees", employeesRevConfig },
{ "Products", productsRevConfig }
},
Default = defaultRevConfig
};
// Execute the operation to update the database
documentStore.Maintenance.Send(new ConfigureRevisionsOperation(northwindRevConfig));
// Create a configuration for the Employees collection
var employeesRevConfig = new RevisionsCollectionConfiguration()
{
MinimumRevisionAgeToKeep = new TimeSpan(hours: 1, minutes: 23, seconds: 45),
MinimumRevisionsToKeep = 42,
PurgeOnDelete = true
};
// Create a configuration for the Products collection
var productsRevConfig = new RevisionsCollectionConfiguration()
{
Disabled = true
};
// Create a default collection configuration
var defaultRevConfig = new RevisionsCollectionConfiguration()
{
MinimumRevisionAgeToKeep = new TimeSpan(days: 7, 0, 0, 0),
MinimumRevisionsToKeep = 100,
PurgeOnDelete = false
};
// Combine to create a configuration for the database
var northwindRevConfig = new RevisionsConfiguration()
{
Collections = new Dictionary<string, RevisionsCollectionConfiguration>()
{
{ "Employees", employeesRevConfig },
{ "Products", productsRevConfig }
},
Default = defaultRevConfig
};
// Execute the operation to update the database
await documentStore.Maintenance.SendAsync(new ConfigureRevisionsOperation(northwindRevConfig));