| Feature | Description |
|---|---|
| Document Model | Data stored in flexible, self-describing JSON-like documents. |
| Schema-less | Documents in a collection can have different structures. |
| Indexing | Supports various index types (single field, compound, text, geospatial). |
| Replication | Supports replica sets for high availability and failover. |
| Sharding | Horizontal scaling by partitioning data across multiple servers. |
| Aggregation Framework | Powerful tools for data processing and transformation. |
| Ad hoc Queries | Rich query language supporting filtering, sorting, projection. |
| Horizontal Scalability | Designed to scale across many servers easily. |
Example document:
{
"_id": ObjectId("507f1f77bcf86cd799439011"),
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "New York"
},
"hobbies": ["reading", "gaming"]
}
| Operation | Example Command |
|---|---|
| Create | db.users.insertOne({name: "Alice", age: 25}) |
| Read | db.users.find({age: {$gt: 20}}) |
| Update | db.users.updateOne({name: "Alice"}, {$set: {age: 26}}) |
| Delete | db.users.deleteOne({name: "Alice"}) |
Indexes improve query speed.
Types of indexes:
Example of creating an index:
db.users.createIndex({age: 1})
$lookup).Example:
db.orders.aggregate([
{ $match: { status: "shipped" } },
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } }
])
| Aspect | Description |
|---|---|
| Type | NoSQL document database |
| Data Model | Collections and JSON-like documents |
| Query Language | Rich query with JSON syntax |
| Scalability | Horizontal (sharding) and vertical |
| Replication | Replica sets for fault tolerance |
| Schema | Schema-less / flexible |
Open this section to load past papers