Professional Documents
Culture Documents
Mongo DB Commands
Mongo DB Commands
show dbs :
databases list هيعرض
db.createCollection('collection_name',other options) :
collection النشاء
other options ... capped - size - autoIndexd max all بالنسبه ل
optional
show collections :
collections هيعرض كل
db.collection_name.drop() :
معينهcollection لحذف
db.dropDatabase() :
لحذف الداتا بيز بالكامل
db.collection_name.insert(document or map) :
معينهcollection داخلdocument الضافه
db.collection_name.insert([document,another document]) :
ف سطر واحدdocument الضافه اكتر من
: document == json or map or object الحظ
db.collection_name.save(document) :
بالضبط انما لوinsert عادي زيdocument مش موجود هتعمل اضافه للid لو
document علي الداتا اللي فupdate موجود ف هتعمل
db.collection_name.find() :
collection داخلdocuments هيعرض كل
db.collection_name.find().pretty() :
بس بشكل كويس تحت بعضdocuments هيعرض كل
db.collection_name.findOne() :
واحده بسdocument هيجيب
: Options
db.collection_name.find({$and,[{'name':'Mohamed Hashim'},{'id':'1'}]}) :
بس الزم االتنين يكونوا موجودين فparameters 2 بناء عdocument كده هجيب
غير كده مش هتنعرضdocument
db.collection_name.find({$or,[{'name':'Mohamed Hashim'},{'id':'1'}]})
دول اتحققparameters 2 لو واحد منdocument هيجيب
** update data
db.collection_name.update({'name':'Mohamed'},{$set,{'name':"Saleh Gomaa"}}) :
هيعمل لهاfield => name == Mohamed اللي فيهاdocument هنا هيروح لل
Saleh Gomaa فقط وهيصبحname اللي اسمهfield بس للupdate
db.collection_name.update({'name':'Mohamed'},{$set,{'name':"Saleh Gomaa"},{'multi':true}) :
parameter => multi الن استعملتmohamed الي شخص اسمهupdate هيعمل
: true
db.collection_name.remove({'name':'Mohamed'}) :
Mohamed تبعها بيحتوي عfield الليdocument هيحذف
db.collection_name.remove({'name':'Mohamed'},1) :
بتحتوي ع نفسdocument واحده بس حتي لو وجد اكتر منdocument هيحذف
field داخلvalue
** projection
db.collection_name.find({},{name:1}) :
+ name field _ بالقيمه تبعهid field بس هيعرض فقطdocuments كده هيجيب كل
بالقيمه تبعه
db.collection_name.find({},{name:1,_id:0}) :
name field with its value بس هيعرض فقطdocuments كده هجيب كل
db.collection_name.limit(3) :
documents 3 هيعرض فقط
db.collection_name.skip(3) :
رقمdocument من اولdocuments بعدين هيعرضdocuments 3 هيتجاهل اول
اربعه
sorting ...
تصاعدي1 mean
تنازلي-1 mean
db.collection_name.find().sort({name:-1}) :
بناء ع التريبname بس بترتيب معين هيكون تنازلي من حيثdocuments هيعرض
االبجدي هيجيب الحروف اللي ف االخر يعني
: مثال اخر
القيمه المخزنهage تصاعدي بناء عdocuments كده هيعرضsort({age:1})
بداخله
db.collection_name.distinct("name")
array بس داخلname اللي اسمهاfield كلها الخاصه بvalues هيعرض
db.collection_name.count()
collection اللي فdocuments هيجيب عدد
db.collection_name.find({name:{$in,['Mohamed',"Ali"]}}) :
هيعرض documentsفقط اللي valueتبع nameفيها تساوي Mohamed or Ali
خلي بالك تساوي***