Java is on the Rise, Be-aware!


Improving scalable Java application development with MongoDB + Morphia:

Over the last year I have seen a significant rise in the number of questions and interest from both the greater Java community and enterprise Java shops about MongoDB. Coming from the MongoDB and Java worlds (among others), this is something I have watched with great interest and excitement.

As one of the authors and project leads for Morphia(MongoDB Java ORM) I have seen a lot of questions relating to both the core driver and how to build Java applications with MongoDB. A lot of these questions arise from the paradigm shift users experience when moving from the standard SQL/JPA/Hibernate platforms/frameworks to the document oriented world of MongoDB.

For the last year or so, Morphia has – how long that seems looking back – bridged the gap between the document/map/dictionary world of the core MongodDB Java driver with the cleaner POJO (domain objects) design pattern, which is much friendlier for business logic.

Over the last few months, the Java MongoDB ecosystem has started to drastically evolve. New features in the core MongoDB server continue to distinguish the product from the crowd and new engineers are joining the MongoDB open source community by contributing Java persistence (mappers) frameworks and libraries.

As one of the main authors of Morphia, I envision many of the projection/mapping features which we have implemented being included in the core MongoDB Java driver, similar to what other drivers support (.Net/C#, and dynamic languages).

Even before I joined 10gen I had been in discussions of how to best integrate the user experience from high-level abstractions such as the JPA EntityManager and DAO pattern into the features supplied with the basic driver. Now that I am a member of the team, and have direct access to the driver (and the great team that has been maintaining it internally, along with the numerous community patches), I am finally in a great position to help make that integration possible. I will in fact be in the best position of all to make this vision come true: I get to do the integration :-)

Major Version Changes

Let’s talk a little about the changes coming in the 3.0* Java driver. First, we have some great ideas of how to improve overall performance for frameworks; these ideas primarily have come from the need to reduce the impedance mismatch of the current driver when being used from frameworks like Morphia, Casbah, and many others.

One of the performance improvements we have in mind will allow us to remove the need to decode binary BSON, to a temporary java map (DBObject) and then to the final format. In some of the very high volume and real-time analytics deployments, this will be an amazing performance improvement. In addition to reduced latency, the change will also reduce resource allocation as well.

A little code:

With Morphia, and soon the driver, you can do things like this:

@Entity class Customer { @Id ObjectId id; String name; String[] projects; } 

Save, and find, a single Model/Entity

Datastore ds = …; Customer(“Scott Hernandez”, new String[]{“java”, “morphia”, “casbah”})); // QBE(query by example) Customer scott = ds.find(Customer.class, new Customer(“Scott Hernandez”)).get(); //Iterate over all customers for(Customer customer : ds.find(Customer.class)) print(customer); 

Use the fluent query interface.

//Use the fluent query interface Query<Customer> findMe = ds.find(Customer.class).field(“projects”).equal(“java”); Customer scott = findMe.get(); //The query is validated by your java class = “Scott D. Hernandez”; //change a field; //save the whole object 

Update just a field or two at a time.

//Update on one field, without needing the full customer object UpdateOperations<Customer> updates = ds.createUpdateOperations(); updates.add(“projects”, “support”); UpdateResults<Customer> res = ds.updateFirst(findMe, updates); 

Coming very soon we will have better support for mock frameworks and testing isolation by providing interfaces to the major components in the driver. Many (open source) projects built on the driver already have support for mock and isolated testing so having the driver support is a great benefit for all.


On the path to these changes we have many other milestones to hit as well. Some of these are internal changes while others will have some outwardly facing impact. The premier goal we have is to make sure that the MongoDB Java driver stays backwards compatible; this will reduce the need for existing applications and deployments to make any changes as we make improvements. There will be some changes that might not fit in this goal but we will keep them as small as possible and highlighted in the release notes.

Events and More Content

Java Web Apps Webinar, May 12, 1:30p ET/ 10:30a PT

We will be hosting an online webinar to talk about one way to build webapps using Java and some common open source frameworks (Guice, Stripes and Morphia) in about week.

You can learn more and register here:

MongoSF + MongoNYC

MongoSF is a one day conference dedicated to MongoDB on May 24th. There will be loads of talks, including a bunch about MongoDB with Java and Morphia. Find out more about the event and registration at Register soon, because it’s nearly sold out already.

MongoNYCwill be held on June 7th and will contain a very similar number of tracks for those on the other coast.

More Blogs

This is just the start of the blogging about the changes coming to the Java driver. There will be many more in-depth posts regarding parts of the driver and interfaces changes.


I can be contacted via email as scott -at- 10gen (dotcom).

Please feel free to submit patches or file issues: