NoSQL
Not Only SQL
- Pronunciation
- noh-ES-kyoo-EL or noh-SEE-kwul
In short
NoSQL is a family of databases that store data in models other than relational tables, such as documents, key-value pairs, wide columns, or graphs.
What is NoSQL?
NoSQL is an umbrella term for databases that do not use the traditional relational model of tables linked by keys. The name is usually read as 'not only SQL', because many of these databases still offer query languages, and some even support SQL-like syntax.
There are four main types. Document databases such as MongoDB store JSON-like documents; key-value stores such as Redis map each key to a value, like a giant dictionary; wide-column stores such as Apache Cassandra organize data into flexible columns spread across many machines; and graph databases such as Neo4j store nodes and the relationships between them.
NoSQL databases became popular for large web applications because many of them are designed to scale horizontally, meaning they spread data across many servers, and they often allow a flexible schema, so records in the same collection can have different fields. They are common for caching, user sessions, real-time analytics, product catalogs, and social networks.
SQL versus NoSQL is a trade-off, not a contest. Relational databases enforce a strict schema and excel at complex queries and multi-row transactions, while NoSQL databases trade some of those strengths for flexibility, scale, or speed in specific access patterns. Today the line is blurrier: many NoSQL databases support transactions, and relational databases like PostgreSQL can store and query JSON.
At a glance
Key takeaways
- NoSQL means 'not only SQL', not 'no SQL at all'.
- The main types are document, key-value, wide-column, and graph databases.
- Many NoSQL databases scale horizontally across many servers.
- Schemas are usually flexible, so records can have different fields.
- Choosing SQL or NoSQL depends on your data and how you query it.
Example
// Using the MongoDB Node.js driver
const users = db.collection("users");
// Documents in the same collection can have different fields
await users.insertOne({ name: "Ada", skills: ["math", "code"] });
await users.insertOne({ name: "Linus", country: "Finland" });
// Find users whose skills array contains "code"
const coders = await users.find({ skills: "code" }).toArray();Readers ask
What is the difference between SQL and NoSQL?
SQL databases store data in tables with a fixed schema and use SQL for queries, while NoSQL databases use other models such as documents or key-value pairs, usually with a flexible schema. SQL databases are strong at complex queries and consistency; NoSQL databases are often chosen for flexibility and horizontal scale.
Is MongoDB a NoSQL database?
Yes. MongoDB is a document database, one of the most widely used types of NoSQL database, and it stores data as JSON-like documents.
Do NoSQL databases support transactions?
Many modern NoSQL databases, including MongoDB, support multi-document transactions, though the guarantees vary by product. Historically, many NoSQL systems only guaranteed atomic changes to a single record.
Often compared
See also
- DatabaseDatabases, p. 6A database is an organized collection of data stored on a computer, managed by software that lets applications save, search, and update it efficiently.
- SQLDatabases, p. 40SQL is the standard language for working with relational databases, used to create tables and to insert, query, update, and delete the data stored in them.
- JSONBackend & APIs, p. 25JSON is a lightweight, text-based format for storing and exchanging structured data as key-value pairs and lists, readable by both humans and machines.
- TransactionDatabases, p. 47A transaction is a group of database operations that succeed or fail as a single unit, so the data is never left in a half-finished, inconsistent state.
- MicroservicesSoftware Architecture, p. 27Microservices are an architectural style where an application is split into small, independently deployable services that communicate over a network.
- CAP TheoremDatabases, p. 2The CAP theorem says that if a network failure splits a distributed database, the system must choose between consistency and availability; it can't have both.
- MongoDBDatabases, p. 26MongoDB is a document database that stores data as flexible JSON-like documents instead of table rows, so records in one collection can have different fields.
- RedisDatabases, p. 37Redis is an in-memory key-value store that reads and writes in well under a millisecond, which makes it a popular cache, session store and message broker.
- DynamoDBDatabases, p. 16Amazon DynamoDB is a fully managed NoSQL database on AWS that stores items by key, scales automatically and answers lookups in single-digit milliseconds.
- Graph DatabaseDatabases, p. 23A graph database stores data as nodes connected by relationships, which makes it fast to follow links such as friends of friends or dependencies between items.
Spotted a mistake or something missing on this page?Suggest an edit