{
"_id": ObjectId("60c72b2f5f1b2b001f9b6b74"),
"name": "Alice",
"age": 25,
"address": {
"street": "123 Main St",
"city": "New York"
},
"tags": ["developer", "mongodb"]
}
db.orders.aggregate([
{ $match: { status: "Shipped" } },
{ $group: { _id: "$customer_id", totalSpent: { $sum: "$amount" } } }
]);
db.users.createIndex({ "email": 1 });
db.users.updateOne(
{ _id: ObjectId("60c72b2f5f1b2b001f9b6b74") },
{ $set: { age: 26 } }
);
db.orders.aggregate([
{ $match: { status: "Delivered" } },
{ $group: { _id: "$customer_id", totalSpent: { $sum: "$amount" } } },
{ $sort: { totalSpent: -1 } }
]);
db.places.createIndex({ location: "2dsphere" });
Feature | Description |
---|---|
Document-Oriented | Store data as flexible documents (JSON-like objects). |
Schema-less | No need to define a schema upfront; each document can have its own structure. |
Horizontal Scaling | Data can be distributed across multiple servers using sharding. |
Replication | Replica sets provide high availability and automatic failover. |
Rich Query Language | Support for a wide range of queries, including range queries, text search, and more. |
Aggregation Framework | Advanced data processing capabilities for real-time analytics and reporting. |
Indexes | Create indexes on any field to optimize query performance. |
Data Consistency | Use write and read concerns to ensure data consistency and integrity. |
Real-Time Data Processing | Optimized for real-time data processing and handling large volumes of data. |
Geospatial Indexing | Support for location-based queries and spatial data. |
Cloud Integration | MongoDB Atlas offers a fully managed cloud service for easy deployment and scaling. |