RavenDB: Bundles, Cascade Deletion, Document Versioning

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.

RavenDB Bundle

RavenDB Bundle

 

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:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

It’s also possible to delete attachments with this functionality:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
RavenDB Cascade Delete

RavenDB Cascade Delete

 

Document Versioning

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:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

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:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
RavenDB Revisions

RavenDB Revisions

 

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:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

The revision number is just attached to the document id:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

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:

Could not embed GitHub Gist 1195751: API rate limit exceeded for 208.113.160.6. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Conclusion

RavenDB Bundles give us optional, useful features. Make sure that you look for a bundle before implementing some functionality yourself.

Tagged on: ,

2 thoughts on “RavenDB: Bundles, Cascade Deletion, Document Versioning

  1. gamlerhart Post author

    Hmm, I never tried to remove them. I don’t know.

    Maybe once you’ve removed the versioning bundle, you can delete them?

    RavenDB also has got a lot of fine tuning since I wrote this, and I’m not up to date anymore.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>