Don't Use MongoDB For The Wrong Things

The early phases of a greenfield project always seem to conjure up grand ideas of how to use the hottest new technologies to accomplish your goals. Many times, these grandiose plans give way to a more level-headed design discussion where more realistic technologies are adopted. However, there are a few times where the developer with the idea to use the hottest new technology is the one in charge, and ends up getting his way.

Unfortunately, this seems to happen too often in the NoSQL vs RDMS wars. It seems many of the proponents of a NoSQL solution seem to think that you can use your favorite NoSQL datastore, say MongoDB, as a replacement for a relational database. Granted, there are many situations where MongoDB would be an adequate solution for your project and where a relational database would be overkill. However, these scenarios are a lot less common than many seem to think.

Don’t try to innovate with the platform you are building your solution with, innovate with your solution.

When working with a NoSQL solution such as MongoDB, the danger lies in trying to use MongoDB in a project that has an immense amount of related data. While it may seem like a CMS would be a perfect situation to utilize MongoDB, in reality, there are quite a few relationships that exist in even the most basic of websites. Many times, pages are grouped into categories, and then further grouped by date and/or author. It may seem trivial to just add this information to the document that is stored for each page, but if you need to update the author’s name on all of the posts that they wrote because they had a change in their legal name, it would take some work to update each page’s document. If, however, you wanted to show all of the pages that a single author contributed to, you can still do it in MongoDB, but it just adds another level of relationship to data that is supposed to not be relational.

The scenario that you absolutely do not want to use MongoDB is when you are working with financial or other multi-part transactions that must either go all the way through to completion or return an error and save no history of the transaction’s effects on the data moving forward. An eCommerce platform would be a perfect example of when you absolutely want transactions to complete for an entire sales order instead of partial completions. A partially complete sales order would cause developers many lost hours trying to figure out which customer tried to order which product and with which payment method that got lost. Relational database systems provide a standardized method for doing this, allowing developers to base their designs on industry best practices.

While there are valid use cases for MongoDB and other NoSQL database stores, they are not the right choice for many projects. Don’t try to innovate with the platform you are building your solution with, innovate with your solution.

Related Posts

Mar 23, 2015
2 minutes

Google Chrome Improves JavaScript Speeds Again

One of the old rules of optimizing website load times for all browsers was that the browser didn’t begin to parse the downloaded JavaScript until each file was downloaded. Starting with Chrome 41, Google has announced that this is no longer the case.

In this announcement, Google has said that new versions of Chrome will begin parsing JavaScript as it is downloaded to the browser, even before the particular file’s download is complete. However, in order to see this happen more quickly, you must utilize the async or deferred tags in the <script> tag. JavaScript that is loaded without async or deferred is still a completely blocking action that pauses all rendering while downloading and parsing the JavaScript files. According to Google, this can improve website load time by up to 10%.

May 14, 2014
2 minutes

Responsive Images with Picturefill 2.0

Responsive Web Design seems to be the way that the majority of websites will be developed in the near future. For a while, everyone was creating a separate website that catered to mobile devices in addition to the main website that desktop browsers were able to access. Web Developers and UX Designers quickly discovered that this was a less than ideal approach as it required maintaining two separate websites, and the mobile website tended to remove data that was visible on the desktop version of the site.

Apr 6, 2015
2 minutes

Write Your Own Compass Mixin

As a developer working with CSS, one of the things that I find a bit troubling is the amount of style definitions that I have to repeat over and over to achieve the design I desire. One of the basic tenets of software development is to utilize the DRY principle, otherwise known as Don’t Repeat Yourself. Fortunately, when you implement Compass and SASS in your project to generate your CSS, you have a way to avoid copy-paste programming.