What is MongoDB?
MongoDB is a NoSQL document database storing JSON-like documents.
CRUD
db.users.insertOne({name: "Alice", age: 25});
db.users.find({age: {$gt: 20}});
db.users.updateOne({name: "Alice"}, {$set: {age: 26}});
db.users.deleteOne({name: "Bob"});
Aggregation
db.orders.aggregate([
{$match: {status: "done"}},
{$group: {_id: "$userId", total: {$sum: "$amount"}}},
{$sort: {total: -1}}
]);
Summary
- MongoDB stores flexible JSON documents
- Aggregation pipeline processes data in stages
YouTip