MongoDB
In one line
MongoDB is a NoSQL document database that stores data as flexible JSON-like documents (BSON) in collections.
In simple words
MongoDB is a popular NoSQL document database. Instead of tables and rows, it stores documents (JSON-like objects) in collections. Each document can have any fields — there is no fixed schema.
For example, a users collection might contain:
{ "name": "Ada", "email": "ada@example.com", "skills": ["math", "code"] }
{ "name": "Grace", "email": "grace@example.com", "rank": "admin" }
Notice the two documents have different fields — MongoDB allows this. You query with a JSON-based query language (not SQL), though many tools provide SQL-like interfaces.
MongoDB is good for:
- Rapidly changing data shapes
- Horizontal scaling (sharding)
- Storing nested or hierarchical data
It trades some query power and consistency guarantees for flexibility and scale.
Example
// Insert a document
db.users.insertOne({
name: "Ada Lovelace",
email: "ada@example.com",
skills: ["math", "programming"]
});
// Query documents
db.users.find({ skills: "math" });MongoDB stores flexible documents. The query finds all users who have 'math' in their skills array.
Related terms
Related Resources
Related Lessons
- MongoDB Basics
Learn MongoDB fundamentals.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.