Versioned objects in MongoDB
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This project explores mechanisms to manage versioned data. For example, some data is bound by historical retention policies or user rollback functionality. In order to accomplish this, it's necessary to ensure that previous versions of an object are retained.

This work leverages MongoDB and builds on the structure outlined here:

The schemaless document structure of MongoDB provides a lot of flexibility with respect to storing multiple versions of the same object.

This implementation focuses on Java using Morphia ( as a mapping technology. I also leverage Guice for dependency injection (

Grab the code and run the unittests or fire up a MongoDB server and run to see how it works.

Basic usage:

Injector injector = Guice.createInjector(new MorphiaModule());

// get a PersonDAO
PersonDAO personDao = injector.getInstance(PersonDAO.class);

// create a person object
PersonNameFactory personNameFactory = injector.getInstance(PersonNameFactory.class);
PersonFactory personFactory = injector.getInstance(PersonFactory.class);

PersonName name = personNameFactory.create("Danny", "Watrous");
Person publishedPerson = personFactory.create(name, 15, "", true);

// save a new Person;

// get the person we just saved above
Person retrievedPerson = personDao.getPersonByName(name);

// update and safe Draft

// or publish (this automatically manages history)

Some additional discussion of this project and a description of my design goals is provided here: