🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

MongoDB संपूर्ण गाइड 2026: सीआरयूडी, एकत्रीकरण और उत्पादन पैटर्न

⏱️3 min read  ·  463 words

MongoDB दुनिया का सबसे लोकप्रिय NoSQL डेटाबेस है। 2026 में, MongoDB 8.0 प्रमुख प्रदर्शन सुधार और बेहतर डेवलपर टूल लाता है। यह संपूर्ण मार्गदर्शिका आपके पहले दस्तावेज़ से लेकर उत्पादन-ग्रेड MongoDB आर्किटेक्चर तक सब कुछ शामिल करती है।

MongoDB क्यों?

  • लचीली स्कीमा– डेटा मॉडल विकसित करने के लिए कोई माइग्रेशन नहीं
  • JSON जैसे दस्तावेज़– जावास्क्रिप्ट/पायथन एपीआई के लिए प्राकृतिक फिट
  • क्षैतिज स्केलिंग– बड़े पैमाने पर डेटा के लिए अंतर्निहित शार्डिंग
  • समृद्ध क्वेरी भाषा– एकत्रीकरण पाइपलाइन एनालिटिक्स के लिए एसक्यूएल को प्रतिद्वंद्वी बनाती है
  • एटलस वेक्टर खोज– एआई अनुप्रयोगों के लिए अर्थ संबंधी खोज

इंस्टालेशन

# macOS
brew tap mongodb/brew && brew install mongodb-community@8.0
brew services start mongodb-community@8.0

# Ubuntu 24.04
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
sudo apt update && sudo apt install -y mongodb-org
sudo systemctl start mongod

# Connect to shell
mongosh

कोर सीआरयूडी संचालन

// Switch database
use techpulse_db

// INSERT
db.users.insertOne({
  name: "Alice",
  email: "alice@example.com",
  skills: ["Python", "React"],
  createdAt: new Date()
})

db.posts.insertMany([
  { title: "React Guide", views: 1500, tags: ["react", "js"] },
  { title: "Python Guide", views: 2300, tags: ["python", "backend"] }
])

// FIND
db.users.find({ skills: "Python" })     // match array element
db.posts.find(
  { views: { $gt: 1000 } },            // filter
  { title: 1, views: 1, _id: 0 }       // projection
)

// UPDATE
db.users.updateOne(
  { email: "alice@example.com" },
  { $set: { role: "senior" }, $push: { skills: "Go" } }
)
db.posts.updateMany(
  { tags: "python" },
  { $inc: { views: 100 } }
)

// DELETE
db.users.deleteOne({ email: "alice@example.com" })

प्रदर्शन के लिए सूचकांक

// Check slow queries
db.posts.find({ title: "React Guide" }).explain("executionStats")

// Create indexes
db.users.createIndex({ email: 1 }, { unique: true })
db.posts.createIndex({ tags: 1, views: -1 })       // compound
db.articles.createIndex({ title: "text" })           // full-text search
db.events.createIndex({ createdAt: 1 },
  { expireAfterSeconds: 2592000 })                    // TTL: 30 days

// Always create indexes before going to production
db.users.getIndexes()

एकत्रीकरण पाइपलाइन

// Sales report: revenue by category
db.orders.aggregate([
  { $match: { status: "completed", createdAt: { $gte: new Date("2026-01-01") } } },
  { $unwind: "$items" },
  { $group: {
    _id: "$items.category",
    totalRevenue: { $sum: { $multiply: ["$items.price", "$items.qty"] } },
    count: { $sum: 1 }
  }},
  { $sort: { totalRevenue: -1 } },
  { $limit: 10 },
  { $project: { category: "$_id", revenue: { $round: ["$totalRevenue", 2] }, _id: 0 }}
])

पायमोंगो और मोटर के साथ पायथन (Async)

from pymongo import MongoClient, ASCENDING
from datetime import datetime

# Sync
client = MongoClient("mongodb://localhost:27017/")
db = client.techpulse_db
users = db.users

result = users.insert_one({"name": "Alice", "createdAt": datetime.utcnow()})
alice = users.find_one({"name": "Alice"}, {"_id": 0})
users.update_one({"name": "Alice"}, {"$set": {"active": True}})

# Async with Motor (for FastAPI)
import motor.motor_asyncio

async_client = motor.motor_asyncio.AsyncIOMotorClient("mongodb://localhost:27017")
async_db = async_client.techpulse_db

async def create_user(data: dict) -> str:
    result = await async_db.users.insert_one(data)
    return str(result.inserted_id)

async def list_users(page: int = 1) -> list:
    cursor = async_db.users.find().skip((page-1)*20).limit(20)
    return await cursor.to_list(length=20)

डेटा मॉडलिंग: एंबेड बनाम संदर्भ

// Embed when reading together (1-to-few)
{
  _id: ObjectId("..."),
  title: "MongoDB Guide",
  author: { name: "Alice", email: "alice@blog.com" },  // embedded
  tags: ["mongodb", "nosql"]                            // embedded
}

// Reference when shared/large (1-to-many)
// posts: { authorId: ObjectId("user1") }
// Look up with $lookup
db.posts.aggregate([
  { $lookup: {
    from: "users",
    localField: "authorId",
    foreignField: "_id",
    as: "author"
  }},
  { $unwind: "$author" }
])

उत्पादन की सर्वोत्तम प्रथाएँ

  • प्रतिकृति सेट का प्रयोग करें– एचए के लिए न्यूनतम 3 नोड्स
  • प्रमाणीकरण सक्षम करें– प्रमाणीकरण के बिना कभी भी MongoDB न चलाएं
  • दस्तावेज़ों को मान्य करें– JSON स्कीमा या पाइडेंटिक का उपयोग करें
  • धीमी क्वेरीज़ पर नज़र रखें– प्रोफाइलर सक्षम करें, एटलस मॉनिटरिंग का उपयोग करें
  • दस्तावेज़ का आकार सीमित करें– 16एमबी बीएसओएन सीमा के अंतर्गत रहें
  • उत्पादन के लिए एटलस– बैकअप, स्केलिंग, मॉनिटरिंग के साथ प्रबंधित सेवा

# Atlas connection
MONGO_URI = "mongodb+srv://user:pass@cluster.mongodb.net/mydb?retryWrites=true&w=majority"
client = MongoClient(MONGO_URI)

2026 में MongoDB 8.0 लचीले, तेज़ अनुप्रयोगों के लिए सबसे अच्छा दस्तावेज़ डेटाबेस है। सरल शुरुआत करें, उचित इंडेक्स बनाएं और एनालिटिक्स के लिए एकत्रीकरण पाइपलाइन का उपयोग करें। अपने ऐप्स में AI-संचालित सिमेंटिक खोज के लिए एटलस वेक्टर सर्च के साथ युग्मित करें।

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা