MongoDB is a document-oriented NoSQL database designed for scalability and developer productivity. Its flexible schema and powerful query language make it popular for modern applications.
📑 Table of Contents
Key Features
- Document Model: Store data as JSON-like documents
- Flexible Schema: No predefined structure required
- Aggregation: Powerful data processing pipeline
- Sharding: Horizontal scaling support
- Replication: High availability replica sets
Installation
Install MongoDB on Ubuntu:
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
sudo apt install mongodb-org
sudo systemctl enable mongod
sudo systemctl start mongod
Usage Examples
MongoDB operations:
// Connect and use database
use myapp
// Insert document
db.users.insertOne({
name: "John Doe",
email: "john@example.com",
roles: ["user", "admin"]
})
// Query with filter
db.users.find({ roles: "admin" })
// Aggregation pipeline
db.orders.aggregate([
{ $match: { status: "completed" } },
{ $group: { _id: "$customer", total: { $sum: "$amount" } } }
])
Benefits
MongoDB accelerates development with its flexible data model. Its native JSON support and horizontal scaling make it ideal for evolving applications and big data.
Was this article helpful?