Python MongoDB তৈরি
- পূর্ববর্তী পৃষ্ঠা MongoDB ড্যাটাবেস সৃষ্টি
- পরবর্তী পৃষ্ঠা MongoDB Insert
MongoDB-তে সংগ্রহ SQL ডাটাবেস-এর টেবিলের মতোই।
সংগ্রহ তৈরি করুন
MongoDB-তে সংগ্রহ তৈরি করতে, ডাটাবেস অবজেক্ট ব্যবহার করে এবং তৈরি করতে হলে নাম নির্দিষ্ট করুন。
যদি তা নেই, MongoDB তা সংগ্রহ তৈরি করবে。
ইনস্ট্যান্স
"customers" নামের সংগ্রহ তৈরি করুন:
import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["mydatabase"] mycol = mydb["customers"]
Important tip:In MongoDB, collections are not created before obtaining content!
Before actually 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:
ইনস্ট্যান্স
Return a list of all collections in the database:
print(mydb.list_collection_names())
Or you can check a specific collection by name:
ইনস্ট্যান্স
Check if the "customers" collection exists:
collist = mydb.list_collection_names() if "customers" in collist: print("The collection exists.")
- পূর্ববর্তী পৃষ্ঠা MongoDB ড্যাটাবেস সৃষ্টি
- পরবর্তী পৃষ্ঠা MongoDB Insert