At SecondMarket, we have been using mongoDB for storing our asset classes and events/notifications for the last year. Mongo was selected for storing assets as our diverse set of asset structures are completely different, yet in mongo, they can all be stored in the same collection due to its schema free nature. In a relational database, each asset class would need to be represented as a separate table, or alternatively, we could store all assets in a single humungous table, that we would need to add columns to as we added new assets. Yuck!!!! Mongo also made sense for storing our events and notifications, due to mongos ability to handle large volumes of data and the ease of which this data can be sharded.

For anyone who has used traditional relational database and came to rely on liquibase for handling database change across environments, not having that tool available for mongo was a headache. This is why mongeez was born. Mongeez is a tool that allows you to modify the structure of your documents and replicate those changes in unison with your code across all your environments from QA to production. Imagine a scenario where you have 10 QA environments, with each team needing different versions of the your code on each environment and different versions of your mongo collections. If you wanted to change the structure of a mongo document, when would be the appropriate time to roll that out to your QA environments? Don’t worry, you’re not expected to know the answer:) What you want to do is, as you deploy the code that works with the new structure, you want to automatically update the underlying mongo structure at the same time. This is what mongeez enables.

Using mongeez is simple. You create a set of mongo javascript changesets that can do things like modify your collection structure or insert data (see below). As you write the scripts to modify your structure, you also modify your code that manipulates the underlying data.

<mongoChangeLog>
    <changeSet changeId="ChangeSet-1" author="mlysaght">
        <script>
            db.organization.insert({
              "Name" : "10Gen”, "Location" : "NYC”, DateFounded : {"Year":2008, "Month":01, "day":01}});
            db.organization.insert({
              "Name" : "SecondMarket”, "Location" : "NYC”, DateFounded : {"Year":2004, "Month":5, "day":4}});
        </script>
    </changeSet>
    <changeSet changeId="ChangeSet-2" author="mlysaght">
        <script>
            db.user.insert({ "Name" : "Michael Lysaght"});
        </script>
        <script>
            db.user.insert({ "Name" : "Oleksii Iepishkin"});
        </script>
    </changeSet>
</mongoChangeLog>

These changes are then committed to your source repository of choice. Mongeez has a utility that when ran on the startup of your application, it checks what changeSets have not been ran in that environment and runs them. This means that whatever version of your software is running on any environment, you will always have the appropriate code and mongoDB collections/data. We find this to be pretty neat!

Where can you find mongeez and get some code samples? Check out the wiki at mongeez.org and examples at Github. Also check out the presentation I gave at last months mongoDB NYC meetup.

-Michael