It's easy to get caught up in the latest buzzwords and use innovative technology, but that can lead to headaches if you use the wrong tool for your task. MongoDB came in hot and established dominance in the NoSQL Database world when they IPO'd in 2018. In this article, we will discuss what NoSQL databases are and how they differ from SQL databases. Afterward, we will touch on what sets MongoDB apart in the NoSQL landscape. We will end with some use cases for MongoDB and discuss common pitfalls when using this database technology.

Table of Contents

  1. NoSQL vs SQL Databases
  2. MongoDB: A Big Fish In a Small Pond
  3. MongoDB Use Cases

Integrate Your Data Today!

Try Xplenty free for 7 days. No credit card required.

NoSQL vs. SQL Databases

MongoDB is a NoSQL database. This means you do not use SQL to interact with data in the database. Instead, you use NoSQL.

The first difference to discuss is vocabulary. In SQL, we use tables. In NoSQL, we use collections. In SQL, tables consist of records/rows, in NoSQL, collections are documents.

To query MongoDB, you need to use NoSQL syntax. Here is an example of a SQL query and the corresponding NoSQL query:

SQL:

SELECT * FROM users WHERE age > 65;

NoSQL:

users.find({age: {$gt: 65} });

You'll notice that the query language treats the collection as an object on which you apply actions. This is because MongoDB is a schemaless database, and it assumes that there will be no need to interact with other collections. SQL syntax expects users to JOIN on other relations in the database, and thus the syntax enables that. There is a similar pattern in trying to INSERT:

SQL:

INSERT INTO users (id, age) VALUES (1, 70);

NoSQL:

users.insert({id: 1, age: 70});

The prominence of a defined schema is clear in the SQL INSERT because the columns you choose have to exist in the users table. With the NoSQL statement, the id and age columns do not have to exist in the collection beforehand. In fact, you can make another INSERT into that collection with different fields. For example, we can run the following command on the same users collection we used above:

users.insert({first_name: "Annie", zip_code: "10005"})

MongoDB, and other NoSQL databases, are schemaless databases. This means that users can store unstructured data. This functionality is both a blessing and a curse - the flexibility makes it easier to store data, yet also makes it more difficult to organize your data.

For an in-depth analysis of the critical differences between SQL and NoSQL, check out this blog post.

Integrate Your Data Today!

Try Xplenty free for 7 days. No credit card required.

Who Should Use MongoDB

For a few years, MongoDB was synonymous with NoSQL in many circles. Between their aggressive marketing campaigns and the ability to make inroads with several technology influencers, they could capture a large swath of this "new" market. As it became more widespread, people poked holes in its viability for certain applications. It became a useful tool for folks who "just wanted to get their application up and running" and worry about analyzing the data later.

This was an acceptable approach and made sense for a lot of software developers. Eventually, the chickens came home to roost, and it turned out that MongoDB wasn't the best option for everyone. Some engineers who adopted MongoDB early could lean into the technology and adapt to its improvements, while many others underwent massive efforts to migrate off of it. As with every piece of software, Your Mileage May Vary (YMMV), so it is imperative to think critically about the services you use.

Other options have emerged in the document-database world. Postgres, for example, unveiled a JSON column type. This allowed for Postgres users to store unstructured data inside a relational database. Redis also emerged as a useful alternative for users who needed a key-value store. You can learn more about the differences between MongoDB and Redis here. And, as happens with most successful software projects, AWS released their own document-database called DocumentDB, which is useful for folks who want to stick with native AWS applications.

Despite the growing competition, MongoDB still reigns supreme in the NoSQL/Document-database world and keeps improving their services, like making it ACID compliant. Also, in supporting cloud applications, MongoDB has been making efforts to support distributed databases and data lakes.

MongoDB Use Cases

MongoDB is a great database for web applications, especially if the application services many users who do not interact with each other. Think financial services applications, where users only need access to their own data. Or a blogging application, where users want to log in and create/edit their own blogs. Users not interacting with each other is the key takeaway. With a relational database, one would have to store information about a user across several tables. When that user logs on, the application would have to make several queries, or complex JOIN queries, to access all the information for that user. With MongoDB's schemaless document-database, you can store all of a user's information together. This would allow for a single query to a single collection, and the front-end can deal with displaying/editing the data.

Another excellent use-case for MongoDB is trying to incorporate many datasets. Its schemaless design allows for flexibility in how you store your data. Thus, you can store data from several data sources (websites, databases, RSS feeds, etc) into one place, and then create services on top of your new database to analyze it all. For example, Xplenty offers this integration for MongoDB.

MongoDB is a great database for integrating geospatial data with other types of data. For example, if "location" is a piece of metadata that you're working with, MongoDB supports GeoJSON types, so you can efficiently store latitude and longitudes. Furthermore, MongoDB supports 2DSphere Indexes, which optimize geometric calculations on sphere.

Conclusion

MongoDB is a powerful database with many capabilities. As a company, they've led the way in popularizing NoSQL and Document databases. As a database, they've expanded our understanding of data storage best practices, and have seeded their way into many applications across the world.

MongoDB also offers a free, open-source version, which is an excellent option for teams on a budget who can stand up a database server on-premises or in the cloud. If you'd like support with this, Xplenty can help. We know the challenges associated with data storage, integration, and analysis. Whether you need guidance choosing the right tools for data storage or assistance migrating your data to your new solution, schedule a call with Xplenty and find out how our user-friendly ETL solution can work for you.