Today we take a look at how we can install additional functionality to RavenDB with bundles. Then we take a brief look at the cascading delete and versioning bundles.
Bundles / Plugins
The default RavenDB installation only includes basic features. More advanced functionality can be installed with bundles, like versioning of documents, expiration of documents, authorization or cascade delete functionality. Take a look at this page for a list of bundles.
A bundle is easy to install. Create a ‘Plugins’ folder next to RavenDB server location and put the bundle-assembly in there. The bundles shipped with RavenDB are in the ‘Bundles’ directory of the RavenDB distribution.
Cascading Deletion Bundle
RavenDB itself doesn’t have any cascading delete functionally. However the cascade delete bundle brings basic support for that. We just need to drop the ‘Raven.Bundles.CascadeDelete.dll’ assembly into the ‘Plugins’ directory and start up the server.
After that we specify which documents are deleted by adding the ids to a special meta-data field. For example we can add ids of comments to the blog post. When the post document is deleted the comment documents will be deleted as well:
It’s also possible to delete attachments with this functionality:
Another functionality that we can add is document versioning. This bundle will keep a copy of the document whenever we store, update or delete a document. This enables us to track changes over time.
Again add the ‘Raven.Bundles.Versioning.dll’ to the Plugins directory to install it on the server. Also add the ‘Raven.Bundles.Versioning.dll’ and the ‘Raven.Client.Versioning.dll’ assembly to your project.
To configure we store a configuration document. The VersioningConfiguration-instance with the Id ‘Raven/Versioning/DefaultConfiguration’ represents the default. When we set the Exclude flag to true, then documents are not versioned by default. Otherwise as many revisions as specified in MaxRevisions are kept:
We can configure the versioning behavior for each document type. We do this by storing a VersioningConfiguration instance with an id which refers to the document collection. Like this:
Accessing the Versions
Now RavenDB starts to version our documents. Versions are just stored as regular documents with a special id. However they are hidden from the indexers, so they don’t show up in any query. So how do we access these documents? We access them by loading them by id. Like this:
The revision number is just attached to the document id:
And how do we find out what the latest revision is? We can use the ‘GetRevisionsFor‘ extension method. We specify the id of the document, where we want to start and how many revisions we want to get. Like this:
RavenDB Bundles give us optional, useful features. Make sure that you look for a bundle before implementing some functionality yourself.
- Updates for db4o LINQPad Driver