Yuklanmoqda...

NoSQL'dan 100 gram

category Web person Neo_Yamaguchi calendar_month 11 Sep 2025, 22:46

🔹 MongoDB asoslari

1. MongoDB nima?

MongoDB — bu document-oriented NoSQL ma’lumotlar bazasi. Ma’lumotlarni JSONga o‘xshash formatda (BSON) saqlaydi.
Misol:

{ "username": "mexroj", "age": 21, "skills": ["python", "pentest", "linux"] } 

2. Asosiy tushunchalar

  • Database (DB) → SQL’dagi database ga o‘xshaydi
  • Collection → SQL’dagi table ga o‘xshaydi
  • Document → SQL’dagi row ga o‘xshaydi (JSON ko‘rinishida)

3. MongoDB buyruqlari

Mongo shell (mongosh) yoki Python/Node.js orqali ishlatiladi.

🔹 Database bilan ishlash

show dbs // barcha DBlarni ko‘rish use mydb // 'mydb' nomli DB yaratish/yoki unga o‘tish db.dropDatabase() // DBni o‘chirish 

🔹 Collection bilan ishlash

db.createCollection("users") // 'users' collection yaratish show collections // mavjud collectionlar db.users.drop() // 'users'ni o‘chirish 

🔹 Document qo‘shish

db.users.insertOne({ name: "Ali", age: 20 }) db.users.insertMany([ { name: "Vali", age: 22 }, { name: "Gulbahor", age: 25 } ]) 

🔹 Document o‘qish

db.users.find() // hammasini chiqaradi db.users.find({ name: "Ali" }) // faqat 'Ali'ni chiqaradi db.users.find({ age: { $gt: 21 } }) // yoshi 21 dan katta bo‘lganlar db.users.findOne({ name: "Vali" }) // bitta document qaytaradi 

🔹 Document yangilash

db.users.updateOne( { name: "Ali" }, { $set: { age: 30 } } ) db.users.updateMany( { age: { $lt: 25 } }, { $inc: { age: 1 } } // yoshni +1 qiladi ) 

🔹 Document o‘chirish

db.users.deleteOne({ name: "Vali" }) db.users.deleteMany({ age: { $gt: 25 } }) 

4. Muhim operatorlar

MongoDB query’larda ishlatiladigan operatorlar:

  • Taqqoslash:

  • $eq → teng (==)

  • $ne → teng emas (!=)
  • $gt → katta
  • $lt → kichik
  • $gte → katta yoki teng
  • $lte → kichik yoki teng

  • Mantiqiy:

  • $and

  • $or
  • $not
  • $nor

  • Array operatorlari:

  • $in

  • $nin
  • $all
  • $elemMatch

5. Misol (oddiy login query)

db.users.insertOne({ username: "admin", password: "secret123" }) db.users.find({ username: "admin", password: "secret123" }) 

Agar kodda input to‘g‘ri filtrlab qo‘yilmasa → injection sodir bo‘lishi mumkin.

chat Izohlar

Hozircha izohlar yo'q.