A NoSQL database is a type of database designed to store and manage data using models other than the traditional relational table model. NoSQL databases are useful for applications that need flexible data structures, scalability, or specialized data access patterns.
NoSQL commonly means "Not Only SQL." These databases can store data in documents, key-value pairs, wide-column structures, or graph structures.
MongoDB is a document-oriented NoSQL database. It stores information in documents rather than requiring every record to follow the same table structure.
Example of a MongoDB document:
{
"name": "Rahul",
"age": 20,
"course": "ADCA"
}
This document contains three fields: name, age, and course.
Modern applications may manage large amounts of structured, semi-structured, or rapidly changing data. NoSQL databases provide different storage models for these requirements.
Stores data as documents containing field-value pairs.
Example: MongoDB
{
"student_id": 101,
"name": "Amit",
"course": "Web Development"
}
Stores data as a key associated with a value.
Example: Redis
student_name: "Amit"
student_course: "ADCA"
Organizes data using rows and flexible groups of columns, making it useful for certain distributed workloads.
Example: Apache Cassandra
Stores data as nodes and relationships. It is useful when connections between entities are important.
Example: Neo4j
| SQL Database | NoSQL Database |
|---|---|
| Commonly stores data in tables | May use documents, key-value pairs, graphs, or wide columns |
| Usually uses a defined relational schema | Schema flexibility depends on the database model |
| Uses SQL for relational database operations | Uses database-specific query methods or languages |
| Relationships often use foreign keys and joins | Relationships may use references, embedded data, or graph connections |
| Example: MySQL | Example: MongoDB |
Data organized according to a defined structure, such as rows and columns in a relational table.
StudentID | Name | Age
101 | Rahul | 20
102 | Amit | 21
Data that uses labels, keys, or other organizational elements without requiring every record to have an identical structure.
{
"name": "Rahul",
"age": 20
}
{
"name": "Amit",
"course": "ADCA"
}
Data that does not naturally fit a fixed tabular structure, such as images, audio, video, and free-form documents. Applications may store these files separately and keep their metadata in a database.
We can create a database and insert a document using
MongoDB Shell (mongosh).
Step 1: Select a database
use school_db
Step 2: Insert a student document
db.students.insertOne({
name: "Rahul",
age: 20,
course: "ADCA"
})
Step 3: Retrieve student documents
db.students.find()
The students collection stores the document.
MongoDB creates the collection automatically when needed
during this insert operation.
Q1. What does NoSQL commonly mean?
Q2. Which of the following is a document database?
Q3. Which database model stores nodes and relationships?