2023-08-14 14:44:07 +03:00
|
|
|
from async_pymongo import AsyncClient
|
2023-08-14 14:51:18 +03:00
|
|
|
from pymongo import GEOSPHERE, MongoClient
|
2023-06-22 14:17:53 +03:00
|
|
|
|
2022-12-20 02:22:32 +02:00
|
|
|
from modules.utils import configGet
|
|
|
|
|
|
|
|
db_config = configGet("database")
|
|
|
|
|
|
|
|
if db_config["user"] is not None and db_config["password"] is not None:
|
2023-03-12 15:59:13 +02:00
|
|
|
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
|
2022-12-20 02:22:32 +02:00
|
|
|
db_config["user"],
|
|
|
|
db_config["password"],
|
|
|
|
db_config["host"],
|
|
|
|
db_config["port"],
|
2023-03-12 15:59:13 +02:00
|
|
|
db_config["name"],
|
2022-12-20 02:22:32 +02:00
|
|
|
)
|
|
|
|
else:
|
2023-03-12 15:59:13 +02:00
|
|
|
con_string = "mongodb://{0}:{1}/{2}".format(
|
|
|
|
db_config["host"], db_config["port"], db_config["name"]
|
2022-12-20 02:22:32 +02:00
|
|
|
)
|
|
|
|
|
2023-08-14 14:44:07 +03:00
|
|
|
db_client = AsyncClient(con_string)
|
2023-08-14 14:51:18 +03:00
|
|
|
db_client_sync = MongoClient(con_string)
|
2022-12-20 02:22:32 +02:00
|
|
|
|
|
|
|
db = db_client.get_database(name=db_config["name"])
|
|
|
|
|
2022-12-20 12:37:42 +02:00
|
|
|
col_users = db.get_collection("users")
|
2022-12-20 02:22:32 +02:00
|
|
|
col_albums = db.get_collection("albums")
|
|
|
|
col_photos = db.get_collection("photos")
|
2022-12-21 00:59:35 +02:00
|
|
|
col_videos = db.get_collection("videos")
|
2023-01-02 16:08:46 +02:00
|
|
|
col_tokens = db.get_collection("tokens")
|
2023-01-07 22:48:43 +02:00
|
|
|
col_emails = db.get_collection("emails")
|
2023-01-02 16:08:46 +02:00
|
|
|
|
2023-08-14 14:51:18 +03:00
|
|
|
db_client_sync[db_config["name"]]["photos"].create_index([("location", GEOSPHERE)])
|