What is MongoDB?
MongoDB is a NoSQL document database that stores data in flexible, JSON-like documents called BSON (Binary JSON). Unlike relational databases that use tables and rows, MongoDB uses collections and documents.
MongoDB is designed for scalability, performance, and developer productivity. It's widely used in modern web applications, especially with Node.js.
- Document-oriented — stores data as JSON-like documents
- Schema-flexible — no rigid table structure required
- Horizontally scalable — built for distributed systems
- Rich query language with aggregation support
- Used by companies like Google, Facebook, eBay, and Adobe
Documents and Collections
In MongoDB, a document is a record (like a row in SQL). A collection is a group of documents (like a table in SQL). Documents are stored in BSON format.
Example
// A MongoDB document (JSON-like)
{
"_id": ObjectId("507f1f77bcf86cd799439011"),
"name": "Alice Johnson",
"email": "alice@example.com",
"age": 28,
"hobbies": ["reading", "coding", "hiking"],
"address": {
"city": "San Francisco",
"state": "CA"
}
}
// Key differences from SQL:
// Table → Collection
// Row → Document
// Column → Field
// JOIN → Embedding or Referencing 