Tags: plugin

MongoMapper Plugin – Versionable

There was a requirement at one of our projects here at Artha42 Innovations Private Limited that our Mongo Mapper documents have inherent versioning so as to be able to track the changes being made and also if required revert the changes to a previous state. Since we’re using MongoMapper, I set out to create a simple plugin for the same to add the required functionality.

Initially, from the initial research I did, I found Shapado had an implementation of exactly what I wanted, however when I studied and understood their implementation in detail, I realized that it doesn’t really work that well in most scenarios, especially the ones we were tackling in our project. Shapado’s versionable allows you to define a set of keys for a document, whose changes would trigger creation of new versions. However in our project we needed to track changes at the complete document level, i.e. even for changes in the associations. Also the versions were embedded within the document itself, which implied that the document would grow in size very rapidly, even though our changes in each iteration could be minor, since each version would literally be a snapshot of the complete document itself.

So we made quite a few design changes in the same, externalized the versions, changed the way one would enable versioning since in our case we wouldn’t be keeping track of changes only in specific keys. Even here, we found that there were certain bottlenecks in the case if there were a whole lot of versions, for which we introduced the :limit feature which allows us to define how many of versions would need to be loaded instead of loading all of them at once.

The result of it was mm-versionable.

If you have any comments, suggestions, requests, queries or feedback, please do let us know in the comments section below.