Migrate to async_pymongo
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
"""Module that provides all database columns"""
|
||||
"""Module that provides all database collections"""
|
||||
|
||||
from pymongo import MongoClient
|
||||
from ujson import loads
|
||||
from async_pymongo import AsyncClient
|
||||
from libbot.sync import config_get
|
||||
|
||||
with open("config.json", "r", encoding="utf-8") as f:
|
||||
db_config = loads(f.read())["database"]
|
||||
f.close()
|
||||
db_config = config_get("database")
|
||||
|
||||
if db_config["user"] is not None and db_config["password"] is not None:
|
||||
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
|
||||
@@ -20,13 +18,7 @@ else:
|
||||
db_config["host"], db_config["port"], db_config["name"]
|
||||
)
|
||||
|
||||
db_client = MongoClient(con_string)
|
||||
db_client = AsyncClient(con_string)
|
||||
db = db_client.get_database(name=db_config["name"])
|
||||
|
||||
collections = db.list_collection_names()
|
||||
|
||||
for collection in ["users"]:
|
||||
if collection not in collections:
|
||||
db.create_collection(collection)
|
||||
|
||||
col_users = db.get_collection("users")
|
||||
|
Reference in New Issue
Block a user