What is MongoDB
MongoDB is a database that stores your data as flexible, JSON-like documents instead of rows in fixed tables.
In this page:
What is MongoDB
MongoDB is an open-source document database. Records are stored as documents made of field and value pairs, grouped into collections, and every document can have its own shape.
It scales horizontally with sharding, replicates for high availability, and is queried with a rich JSON-based language.
Note:
Think of a document as a JavaScript object that lives in the database.
Example: What is MongoDB
test> db.users.insertOne({ name: "Ada", age: 36, skills: ["math", "code"] })
{
acknowledged: true,
insertedId: ObjectId('65a1b2c3d4e5f60718293a4b')
}
test> db.users.findOne()
{
_id: ObjectId('65a1b2c3d4e5f60718293a4b'),
name: 'Ada',
age: 36,
skills: [ 'math', 'code' ]
}
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Thinking MongoDB has no structure at all
- Treating it as a drop-in replacement for SQL tables
- Ignoring indexes because it is schemaless
Chapter Summary
- MongoDB is a document database
- Data lives in JSON-like documents
- Documents are grouped in collections
- It scales out and replicates
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: