By Tomasz Naumowicz
The last few years have seen an explosion in the use of NoSQL databases. With the rise of big data driving mainstream adoption in an ever-growing number of enterprises. NoSQL provider MongoDB’s impending IPO demonstrates the expansion in the market and strong long-term prospects.
However, enterprises are still running much of their infrastructure on relational SQL databases, which provide the backbone of their businesses. Previously SQL and NoSQL databases have been managed as distinct systems, often by physically separated teams. As they both become increasingly mission critical, companies need to manage them together, often inside joint projects.
“Over the last year or so we’ve seen a steady and rapid rise in people wanting to use a combination of the two, particularly MongoDB and SQL, showing the maturity of NoSQL and that it’s moving into the mainstream,” suggests Graham Thomson, co-founder, Studio 3T.
Given that NoSQL and relational databases are built in fundamentally different ways, there are definite challenges that need to be conquered if you are going to use the two together. This piece focuses on five of the major hurdles you need to clear when embracing a polyglot SQL/NoSQL world.
Hurdle 1: Queries
MongoDB’s query language is very different to SQL, leading to a major learning curve to get up to speed. I’ve lost count of the people that have said “If this was SQL, I could just….” Take a simple example – a SQL expression such as:
units >= 160
is expressed in MongoDB as:
{ ‘units’: { ‘$gte’: 160 } }
For those well-versed in SQL, it can feel like as much of a struggle as an English speaker reading Russian Cyrillic script. At the same time there are certain areas where MongoDB is far easier than SQL. For example, there is no need to manually construct your query by concatenating strings, because you can do it directly from your programming language of choice, using the API provided. This at one stroke removes a major pain point. One way to help with these differences is to use an Integrated Development Environment (IDE) that allows you to write SQL queries and converts them automatically into MongoDB, providing an instant, accurate translation to speed up the process.
Hurdle 2: Up to Speed Faster
Even if you are using a tool that automatically converts SQL into MongoDB queries, you are sooner or later going to need to learn how to write your own queries, particularly if you’re going to get the most out of the database. So, make sure you pick an IDE that can convert queries between languages, but can also show you how it has done it—that way it helps you learn and build your knowledge for the future.
Hurdle 3: Auto-Generated Driver Code Minimizes Error
If you are writing an application (app) in a native language such as Java or C#, it is likely to need to interact with your MongoDB database. Manually creating code can be time-consuming and involve learning how to write multiple queries in MongoDB. Instead, look at IDEs that can automatically generate driver code from MongoDB into your language of choice. This removes another potential time sink from adopting MongoDB, helping integrate it more smoothly into your overall workflows.
Hurdle 4: Moving Data from SQL to MongoDB
If you are looking to use SQL and MongoDB databases within your enterprise, you will need to exchange and share data between the two. Importing and exporting MongoDB data can be a tedious task, especially when done from a standard command line interface. Instead, look at ways you can automate the process, again reducing any need for manual effort and the associated risk of bugs creeping in through human error.
Hurdle 5: Exporting from MongoDB
MongoDB is only now entering the mainstream, meaning that many of the business intelligence and visualization tools that SQL DBAs are familiar with don’t have native support for the database. While this gap is likely to be remedied in the future, in the short term the best way around it is to pick a development environment that provides the ability to convert data quickly into the formats that you require.
Major Differences
Underlying all of these points there are two main differences between MongoDB and SQL that often trip people up. “Firstly, the structure of the database itself. When you look at NoSQL you don’t have a big vertical database anymore. Instead, you have an enormous, horizontal, tree-like structure that can handle huge amounts of data. That means that you need to approach it in a different way, particularly when it comes to areas such as data modelling. For previously SQL-only developers, this does represent a shift in mindset, but one that also delivers benefits in terms of flexibility and accelerated time to production when you grasp the underlying difference,” states Thomson.
“Secondly, in a NoSQL database you really need to get the modeling right. MongoDB is designed to run quickly, but the queries you execute and the performance of your app is even faster if you focus on modeling correctly from the beginning. The key is to embrace the different document structure of NoSQL databases—it is not like a relational model. For example, a web app is built around a customer, rather than rows of data in a relational database. Thinking this through and applying it can sidestep performance tuning problems as your MongoDB implementation expands,” he adds.
The rise of NoSQL databases such as MongoDB and its advantages in areas such as big data mean that it is rapidly becoming part of enterprise infrastructure. It is no longer a case of either SQL or NoSQL—organizations need to deploy both, and look at how they can bring the two together to meet their database needs, using the right IDE to deliver maximum benefit.
Tomasz Naumowicz is a co-founder at 3T Software Labs, the makers of Studio 3T, the GUI and IDE for MongoDB . Tomasz’s first code was drawing circles on his C128D, and from there he started to explore the exciting field of computing. He has worked in software development and research, at large enterprises, and small start-ups. Tomasz holds a Master’s degree in Computer Science from the Freie Universtiät Berlin.