To see a more detailed version of this data modeling example, read Mapping Terms and Concepts From SQL to MongoDB.
Differences between RDBMS and NoSQL databases
There are a variety of differences between relational database management systems and non-relational databases. One of the key differences is the way data is modeled in the database. Some key differences of each feature is listed below:
Data modeling
NoSQL: Data models vary based on the type of NoSQL database used — for example, key-value, document, graph, and wide-column — making the model suitable for semi-structured and unstructured data.
RDBMS: RDBMS uses a tabular data structure, with data represented as a set of rows and columns, making the model suitable for structured data.
Schema
NoSQL: It provides a flexible schema where each set of documents/row-column/key-value pairs can contain different types of data. It’s easier to change schema, if required, due to the flexibility.
RDBMS: This is a fixed schema where every row should contain the same predefined column types. It is difficult to change the schema once data is stored.
Query language
NoSQL: It varies based on the type of NoSQL database used. For example, MongoDB has MQL, and Neo4J uses Cypher.
RDBMS: This uses structured query language (SQL).
Scalability
NoSQL: NoSQL is designed for vertical and horizontal scaling.
RDBMS: RDBMS is designed for vertical scaling. However, it can extend limited capabilities for horizontal scaling.
Data relationships
NoSQL: Relationships can be nested, explicit, or implicit.
RDBMS: Relationships are defined through foreign keys and accessed using joins.
Transaction type
NoSQL: Transactions are either ACID- or BASE-compliant.
RDBMS: Transactions are ACID-compliant.
NoSQL: NoSQL is suitable for real-time processing, big data analytics, and distributed environments.
RDBMS: RDBMS is suitable for read-heavy and transaction workloads.
Data consistency
NoSQL: This offers eventual consistency, in most cases.
RDBMS: This offers high data consistency.
Distributed computing
NoSQL: One of the main reasons to introduce NoSQL was for distributed computing, and NoSQL databases support distributed data storage, vertical and horizontal scaling through sharding, replication, and clustering.
RDBMS: RDBMS supports distributed computing through clustering and replication. However, it’s less scalable and flexible as it’s not traditionally designed to support distributed architecture.
Fault tolerance
NoSQL: NoSQL has built-in fault tolerance and high availability due to data replication.
RDBMS: RDBMS uses replication, backup, and recovery mechanisms. However, as they are designed for these, additional measures like disaster recovery mechanisms may need to be implemented during application development.
Data partitioning
NoSQL: It’s done through sharding and replication.
RDBMS: It supports table-based partitioning and partition pruning.
Learn more about data partitioning here.
Data to object mapping
NoSQL: NoSQL stores the data in a variety of ways — for example, as JSON documents, wide-column stores, or key-value pairs. It provides abstraction through the ODM (object-data mapping) frameworks to work with NoSQL data in an object-oriented manner.
RDBMS: RDBMS relies more on data-to-object mapping so that there is seamless integration between the database columns and the object-oriented application code.
To learn more about the differences between relational databases and NoSQL databases, read NoSQL vs SQL Databases.
NoSQL use cases
NoSQL database systems are used in nearly every industry, for real-time analytics, content management, IoT applications, recommendation systems, fraud detection, product catalog management, and much more. Use cases range from the highly critical (e.g., storing financial data and healthcare records) to the more fun and frivolous (e.g., storing IoT readings from a smart kitty litter box).
When should NoSQL be used?
When deciding which database to use, decision-makers typically find one or more of the following factors that lead them to select a NoSQL database:
- Fast-paced Agile development
- Storage of structured and semi-structured data
- Huge volumes of data
- Requirements for scale-out architecture
- Modern application paradigms like microservices and real-time streaming
See When to Use NoSQL Databases and Exploring NoSQL Database Examples for more detailed information on the reasons listed above.
NoSQL database misconceptions
Over the years, many misconceptions about NoSQL databases have spread throughout the developer community. In this section, we'll discuss two of the most common misconceptions.
Misconception: relationship data is best suited for relational databases
A common misconception is that NoSQL databases or non-relational databases don't store relationship data well. NoSQL databases can store relationship data — they just store it differently than relational databases do.
In fact, when compared with relational databases, many find modeling relationship data in NoSQL databases to be easier than in relational databases because related data doesn't have to be split between tables. NoSQL data models allow related data to be nested within a single data structure.
Misconception: NoSQL databases don't support ACID transactions
Another common misconception is that NoSQL databases don't support ACID transactions. Some NoSQL databases, like MongoDB, do, in fact, support ACID transactions.
Note that the way data is modeled in NoSQL databases can eliminate the need for multi-record transactions in many use cases. Consider the earlier example where we stored information about a user and their hobbies in both a relational model and a document store. To ensure information about a user and their hobbies was updated together in a relational database, we'd need to use a transaction to update records in two tables. To do the same in a document store, we could update a single document — no multi-record transaction required.
To learn more about common misconceptions, read Everything You Know About MongoDB is Wrong.
NoSQL query tutorial
You could start with MongoDB, the world's most popular NoSQL database, according to DB-Engines. The easiest way to get started with MongoDB is MongoDB Atlas. Atlas is MongoDB's fully managed database as a service. Atlas has a forever-free tier, which you can use to play around. Check out the MongoDB Atlas tutorial to get started.
You can continue to interact with your data by using the Atlas Data Explorer to insert new documents, edit existing documents, and delete documents.
When you are ready to try more advanced queries that aggregate your data, create an aggregation pipeline. The aggregation framework is an incredibly powerful tool for analyzing your data. To learn more, take the free MongoDB University Course M121 The MongoDB Aggregation Framework.
When you want to visualize your data, check out MongoDB Charts. Charts allow you to create dashboards that are filled with visualizations of your data.
Summary
NoSQL databases provide a variety of benefits, including flexible data models, horizontal scaling, lightning-fast queries, and ease of use for developers. NoSQL databases come in a variety of types, including document stores, key-values databases, wide-column stores, graph databases, and multi-model databases.
MongoDB is the world's most popular NoSQL database. Learn more about MongoDB Atlas, and give the free tier a try.
Excited to learn more now that you have your own Atlas account? Head over to MongoDB University where you can get free online training from MongoDB engineers and earn a MongoDB certification. The Quickstarts are another great place to begin; they will get you up and running quickly with your favorite programming language.