Drupalcon Portland - A Tale of MongoDB

It seems like just yesterday we traveled cross country to the little town of Portland for the annual U.S. Drupalcon.  As we left Baltimore on Sunday morning, we could tell we weren't the only ones going out to Drupalcon.  There were quite a few travelers on the plane with "nice nodes" T-shirts or carrying enough technology with them to run what seemed like a mobile production studio.  As even more Drupal devs joined our flight in Salt Lake City, I knew I was going to the right place.

One of the things I like about Drupal events is their "Birds of a Feather" (BOF) sessions.  For those that don't know, on the first day of the conference the organizers put out a blank white board divided into a grid by room number and time.  Once the white board is put up, it becomes a free for all to sign up for a session that you would like to talk about.  These sessions are informal and relatively small, only 20-40 people, but let attendees discuss things that don't have a designated speaker during the regular conference sessions.  On Wednesday, I co-hosted a BOF session about MongoDB.

At Mindgrub, we use MongoDB in Drupal because of the performance enhancements it provides.  MongoDB is a NoSQL database providing near instant read/write times when queried.  If you have a content type with a lot of fields, you should consider using MongoDB because it will store all those fields on the node object, rather than in separate tables.  As we all sat around discussing the advantages and disadvantages of MongoDB, we heard stories from the developers of Examiner.com and one of the lead developers at 10Gen, the makers of MongoDB.

Both 10Gen, and the development team behind Examiner had interesting stories to tell about the inception of MongoDB into the Drupal world.  We heard stories ranging from incredible ease and success to days of banging heads against the wall because of performance issues.  10Gen was very open about what MongoDB was good for in Drupal and where things still needed work.  At the end of the session, I think we convinced quite a few of the other attendees to at least consider MongoDB for their next Drupal project.

Some of the pros of using MongoDB are:

  • It is fast.  Really fast.
  • You avoid having to join lots of tables together when loading a node
  • Database schemas become very easy to adjust.  Need to store a new piece of data on a node, just save it with the rest of the data
  • Community Support
  • Handles big data very well, especially if that data has a lot of variation in structure

In the interest of full disclosure, some of the cons of MongoDB are:

  • A non-relational database makes doing relationships difficult.  I know this sounds obvious but most people tend to forget it until they try and do a join on an Entity Field Reference.
  • Views integration is provided, but there are some limitations.
  • There are some things in Drupal that don't play nicely with MongoDB.  For example, saving the weights of taxonomy terms in a vocabulary is done using direct database queries which means the MongoDB module can't intercept them and save them properly.  I worked around this by adding my own submit handler and rewriting that code to save the weight in MongoDB.

In the end, MongoDB is a wise choice for you if you have a lot of data or data with a lot of variation.  If you are making a small, static site I would not recommend MongoDB for your project because it is overkill for your project.

Are you using MongoDB or have a question about its integration with Drupal?  I would love to hear your success (or horror) stories and will gladly answer any questions you have.

 

Add new comment