ပြည်သူ့ မိုင်ဂိုဒီဘော့ တွင် အများပြားရှိသည့် အသင်းအုပ် ဖန်တီးပါ:
- အရေးပါ စာကြိုး MongoDB ဘဏ္ဍာင် တည်ဆောက်
- နောက်လိုက် စာကြိုး MongoDB အချက်အလက် ပေါင်းစပ်
မိုင်ဂိုဒီဘော့ တွင် အများပြားရှိသည့် အသင်းအုပ် သည် အဆိုပါ အဆိုပါ အများပြားရှိသည့် ဘဏ္ဍာင်အချုပ် တွင် အချက်အလက် အချုပ် နှင့် အတူ ကွဲပြားသည်:
အများပြားရှိသည့် အသင်းအုပ် ဖန်တီးပါ:
မိုင်ဂိုဒီဘော့ တွင် အများပြားရှိသည့် အသင်းအုပ် ဖန်တီးရန် ဘဏ္ဍာင်အရာရေး အရာကွက် အသုံးပြုပါ နှင့် ဖန်တီးရန် အများပြားရှိသည့် အသင်းအုပ် အမည် သတ်မှတ်ပါ:
အများပြားရှိသည့် အသင်းအုပ် မရှိဘဲရှိလျှင် မိုင်ဂိုဒီဘော့ က အများပြားရှိသည့် အသင်းအုပ် ဖန်တီးပါ:
Example
မည်သည့် "customers" အကြိမ်ဖြစ်သည့် အများပြားရှိသည့် အသင်းအုပ်ထားပါ:
import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["mydatabase"] mycol = mydb["customers"]
Important Note:Collections in MongoDB are not created before content is obtained!
Before creating a collection, MongoDB will wait until you have inserted a document.
Check if the collection exists
Remember: In MongoDB, collections are not created before content is obtained, so if this is your first time creating a collection, you should complete the next chapter (create a document) before checking if the collection exists!
You can check if a collection exists in the database by listing all collections:
Example
Return a list of all collections in the database:
print(mydb.list_collection_names())
Or you can check a specific collection by name:
Example
Check if the "customers" collection exists:
collist = mydb.list_collection_names() if "customers" in collist: print("The collection exists.")
- အရေးပါ စာကြိုး MongoDB ဘဏ္ဍာင် တည်ဆောက်
- နောက်လိုက် စာကြိုး MongoDB အချက်အလက် ပေါင်းစပ်