MongoDB, belge tabanlı (document-oriented) bir NoSQL veritabanıdır. JSON benzeri BSON formatında veri saklar ve özellikle esnek şema yapısı gerektiren uygulamalar için idealdir.
MongoDB vs İlişkisel Veritabanları
| Özellik | MongoDB | MySQL/MariaDB |
|---|---|---|
| Veri Modeli | Belge (document) | Tablo (table) |
| Şema | Esnek (schema-less) | Sabit şema |
| Sorgu Dili | MQL (MongoDB Query) | SQL |
| Ölçeklendirme | Yatay (sharding) | Dikey (genellikle) |
| İşlem Desteği | Multi-document (4.0+) | ACID tam destek |
| Kullanım | Esnek veri, real-time | Yapısal veri, finans |
MongoDB Kurulumu
# Ubuntu 22.04 üzerine MongoDB 7 kurulumu
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] 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 -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongodTemel CRUD İşlemleri
# MongoDB Shell'e bağlan
mongosh
# Veritabanı oluştur/seç
use hostopya_db
# Belge ekleme
db.customers.insertOne({
name: "Ahmet Yılmaz",
email: "[email protected]",
plan: "VDS Pro",
created: new Date()
})
# Sorgulama
db.customers.find({ plan: "VDS Pro" })
db.customers.find({ created: { $gte: new Date("2026-01-01") } })
# Güncelleme
db.customers.updateOne(
{ email: "[email protected]" },
{ $set: { plan: "Dedicated" } }
)
# Silme
db.customers.deleteOne({ email: "[email protected]" })Index Oluşturma
# Tekil index
db.customers.createIndex({ email: 1 }, { unique: true })
# Bileşik index
db.customers.createIndex({ plan: 1, created: -1 })
# Text index (tam metin arama)
db.articles.createIndex({ title: "text", content: "text" })Replica Set Yapılandırma
Yüksek erişilebilirlik için MongoDB Replica Set kullanın:
# mongod.conf
replication:
replSetName: "rs0"
# Replica set başlatma
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongo1:27017" },
{ _id: 1, host: "mongo2:27017" },
{ _id: 2, host: "mongo3:27017" }
]
})MongoDB sunucusu için yüksek performanslı VDS Sunucu paketlerimizi inceleyin.

