Blog'a Dön

MongoDB Nedir? NoSQL Veritabanı Rehberi (2026)

MongoDB belge tabanlı NoSQL veritabanı: CRUD işlemleri, index yönetimi, Replica Set kurulumu ve SQL ile karşılaştırma.

mongodbnosqlveritabanıjsonreplica set

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ı

ÖzellikMongoDBMySQL/MariaDB
Veri ModeliBelge (document)Tablo (table)
ŞemaEsnek (schema-less)Sabit şema
Sorgu DiliMQL (MongoDB Query)SQL
ÖlçeklendirmeYatay (sharding)Dikey (genellikle)
İşlem DesteğiMulti-document (4.0+)ACID tam destek
KullanımEsnek veri, real-timeYapı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 mongod

Temel 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.