When learning MongoDB, one of the most important concepts to understand is the collection. It sits right at the heart of how data is organized and accessed in MongoDB.
In this blog post, we’ll cover what a collection is, how it works, how it differs from tables, and why it’s so powerful in real-world applications.
What Is a Collection in MongoDB?
A collection in MongoDB is a group of documents stored within a database.
Think of the MongoDB data structure like this:
Database
└── Collection
└── Document
└── Fields
In simple terms:
A database contains collections
A collection contains documents
A document contains key–value pairs
MongoDB collections are part of the MongoDB document-oriented data model.
Collection vs Table
Table (Relational Databases – SQL)
A table is a structured storage unit used in relational databases like MySQL, PostgreSQL, or SQL Server.
Data is stored in rows and columns
Every row must follow the same predefined schema
Column names and data types are fixed
Relationships are maintained using primary keys and foreign keys
Best suited for structured data where consistency is critical
Example:
A Users table where every row has the same columns like Id, Name, Email, Age.
Collection (NoSQL Databases – MongoDB)
A collection is a container used in NoSQL databases like MongoDB.
Data is stored as documents (BSON/JSON format)
Documents inside a collection do not require the same structure
Schema is flexible (schema-less)
No joins by default; data is often embedded
Ideal for semi-structured or evolving data
Example:
A users collection where one document has email, another has phone, and another has both
Key Difference
SQL tables enforce a strict schema, while MongoDB collections are schema-flexible.
Key Characteristics of MongoDB Collections
Schema-less (Flexible Schema)
Documents in the same collection do not need to have the same structure.
{ name: "Raj", age: 25 }
{ name: "Amit", skills: ["MongoDB", "Node.js"] }
Both documents can exist in the same collection.
Dynamic Creation
Collections are created automatically when you insert the first document.
db.users.insertOne({ name: "Raj" })
No need to explicitly create a collection.
Stores BSON Documents
Collections store documents in BSON format, which supports rich datatypes like:
ObjectId
Date
Array
Embedded documents
Supports Indexing
Indexes can be created on collections to improve query performance.
db.users.createIndex({ email: 1 })
High Scalability
Collections can be:
Sharded across servers
Replicated for high availability
This makes MongoDB ideal for large-scale applications.
How to Create a Collection
Automatically (Recommended)
use myDatabase
db.products.insertOne({ name: "Laptop", price: 50000 })
Collection products is created automatically.
Manually
db.createCollection("employees")
Used when you want to apply options like validation or capped collections.
Types of Collections in MongoDB
Normal Collection
Standard collection used for most data.
Capped Collection
Fixed-size collection that maintains insertion order.
db.createCollection("logs", { capped: true, size: 1024 })
Useful for logs and audit data.
Time-Series Collection
Optimized for time-based data such as IoT or metrics.
db.createCollection("sensorData", {
timeseries: {
timeField: "timestamp",
metaField: "device"
}
})
Common Collection Operations
| Operation | Command |
|---|---|
| Show collections | show collections |
| Insert document | insertOne() |
| Find documents | find() |
| Update document | updateOne() |
| Delete document | deleteOne() |
| Drop collection | db.collection.drop() |

Join the conversation! Your thoughts help the community grow.