Versioned objects in MongoDB
Switch branches/tags
Nothing to show
Latest commit f33fa49 May 23, 2013 @dwatrous dwatrous identify embedded objects to clean up mongodb
Use of Embedded tag and concreteClass identification eliminates the need
to store class details in Mongo. One question remains about how to do
this with a Map:


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: