34 lines
1014 B
Python
34 lines
1014 B
Python
from async_pymongo import AsyncClient
|
|
from pymongo import GEOSPHERE, MongoClient
|
|
|
|
from modules.utils import configGet
|
|
|
|
db_config = configGet("database")
|
|
|
|
if db_config["user"] is not None and db_config["password"] is not None:
|
|
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
|
|
db_config["user"],
|
|
db_config["password"],
|
|
db_config["host"],
|
|
db_config["port"],
|
|
db_config["name"],
|
|
)
|
|
else:
|
|
con_string = "mongodb://{0}:{1}/{2}".format(
|
|
db_config["host"], db_config["port"], db_config["name"]
|
|
)
|
|
|
|
db_client = AsyncClient(con_string)
|
|
db_client_sync = MongoClient(con_string)
|
|
|
|
db = db_client.get_database(name=db_config["name"])
|
|
|
|
col_users = db.get_collection("users")
|
|
col_albums = db.get_collection("albums")
|
|
col_photos = db.get_collection("photos")
|
|
col_videos = db.get_collection("videos")
|
|
col_tokens = db.get_collection("tokens")
|
|
col_emails = db.get_collection("emails")
|
|
|
|
db_client_sync[db_config["name"]]["photos"].create_index([("location", GEOSPHERE)])
|