Python MongoDB ডাটাবেস তৈরি করুন
- পূর্ববর্তী পৃষ্ঠা MongoDB প্রাথমিক পড়া
- পরবর্তী পৃষ্ঠা MongoDB কলেকশন তৈরি করুন
ডাটাবেস তৈরি করুন
MongoDB-তে ডাটাবেস তৈরি করতে, প্রথমে MongoClient অবজেক্ট তৈরি করুন এবং সঠিক IP এড্রেস এবং তৈরি করতে হলের ডাটাবেস নাম দিয়ে সংযোগ URL নির্দিষ্ট করুন。
যদি ডাটাবেস নেই, MongoDB ডাটাবেস তৈরি করবে এবং সংযোগ স্থাপন করবে。
Instance
mydatabase নামের ডাটাবেস তৈরি করুন:
import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["mydatabase"]
Important Note:In MongoDB, the database will not be created before getting the content!
Before actually creating the database (and collection), MongoDB will keep waiting for you to create at least one collection (table) with at least one document (record).
Check if the database exists
Remember: In MongoDB, the database will not be created before getting the content, so if this is your first time creating a database, you should complete the next two chapters (create collection and create document) before checking if the database exists!
You can check if the database exists by listing all the databases in the system:
Instance
Return the list of databases in the system:
print(myclient.list_database_names())
Or you can check a specific database by name:
Instance
Check if "mydatabase" exists:
dblist = myclient.list_database_names() if "mydatabase" in dblist: print("The database exists.")
- পূর্ববর্তী পৃষ্ঠা MongoDB প্রাথমিক পড়া
- পরবর্তী পৃষ্ঠা MongoDB কলেকশন তৈরি করুন