from pymongo import MongoClient from ujson import loads with open("config.json", "r", encoding="utf-8") as f: db_config = loads(f.read())["database"] f.close() db_client = MongoClient( 'mongodb://{0}:{1}@{2}:{3}/{4}'.format( db_config["user"], db_config["password"], db_config["host"], db_config["port"], db_config["name"] ) ) db = db_client.get_database(name=db_config["name"]) collections = db.list_collection_names() for collection in ["users", "warnings", "scheduler"]: if not collection in collections: db.create_collection(collection) col_users = db.get_collection("users") col_warnings = db.get_collection("warnings") # col_checkouts = db.get_collection("checkouts") # col_trackings = db.get_collection("trackings") # col_authorized = db.get_collection("authorized") # col_transactions = db.get_collection("transactions")