Article

Using NoSQL With MongoDB

October 28, 2015  |  Pluralsight
Using NoSQL With MongoDB
Learn something new. Take control of your career.

Relational database systems have been the default choice for storing your application’s data. After all, data is the lifeblood of your application, and it makes sense to store your data using a technology that has been tried and tested by time itself. In recent years, a new flavor of databases have made a ripple in the database pool of thought — these are known as NoSQL databases. So today, I want to go over what NoSQL is exactly, and then take a look into MongoDB and how it can impact your projects.

So, What Does NoSQL Even Mean?

Chances are, when you first learned to program, you used something like MySQL or PostgreSQL to store your data. These are known as relational database management systems. In a nutshell, these types of databases store data in a way that recognizes the relationships between data, and structures them in order to make use of those relationships. This way of structuring is known as the relational model, and we can interact with these databases by using the query language SQL (tip: Want to learn more about SQL? Check out this blog post, which goes into deeper detail).

Now, let’s dive into NoSQL, which can also be read as “not only SQL.” In general, these databases don’t use SQL as their querying language, don’t follow the relational model, and typically don’t require a schema like relational databases do. There are 4 main types of NoSQL databases — key-value, graph, column, and document-oriented — and the reason for many types of NoSQL databases is that each one seeks to excel for different types of data.

That’s Cool, but Why Use NoSQL?

If you bring up NoSQL in any discussion on databases, you’re bound to receive some hefty opinions on the matter. And it makes sense — data is very important. In most cases, relational databases are a good choice for any application. However, when the data you’re storing starts to affect your site performance, you have to start looking into ways to optimize.  

Allow me to introduce you to the idea of polyglot persistence. If you’re a Harry Potter fan, you might be familiar with the “polyjuice potion” that allows the drinker to morph into someone else. The “poly” part simply means many, and polyglot persistence is the idea of using more than 1 database to save (or persist) your data.

Relational database systems are great, but they aren’t the fastest at everything. For instance, it’s common to authenticate a user, create a session, and then store that session for later retrieval. A lot of developers like to use Redis, a key-value database, to store user sessions, while using a relational database for everything else. This allows for great performance and alleviates some of the stress placed on your main database. So while polyglot persistence might sound like a complicated topic, it’s really just the idea of utilizing different technologies to improve your application.

Enter MongoDB

Here at Code School, we see the value NoSQL databases have to offer. Take MongoDB — a document-oriented database that has gained a lot of attention over the years. Being document oriented, it’s great at storing similar data that might contain different types of information.

A popular use case for MongoDB is the storage of medical records because most likely, each record contains entirely different data. When you store medical records in a relational database, it’s likely you’ll end up having to perform complex joins that could slow down your application and make for a poor experience.

Logging events, like user activity, is another great way to use MongoDB to perform real-time analytics on your site. MongoDB comes with a powerful aggregation framework that enables you to pull data using a variety of tools.

With proper data modeling, you can even use MongoDB with applications that are typically thought of as relational, like blogging platforms. There are endless use cases and problems that MongoDB can help solve, which is a big reason why I like using it.

Give MongoDB a Try

NoSQL databases most likely won’t replace traditional relational database systems, but they can certainly improve the performance and longevity of your application. Want to get started? Play our newest MongoDB course, The Magical Marvels of MongoDB, to cover the fundamentals of MongoDB and learn what it means to be document oriented.

Learn something new. Take control of your career.
Pluralsight

Pluralsight

Pluralsight is the technology skills platform. We enable individuals and teams to grow their skills, accelerate their careers and... See more