Add support for replicated hosts

This commit is contained in:
Zeva Rose 2023-03-21 12:52:12 -06:00
parent 392797c4ae
commit ec4219e5a5

View file

@ -14,7 +14,13 @@ CTC2_INST = MotorAsyncIOInstance()
def connect(
host: str, username: str, password: str, port: int = 27017, testing: bool = False
username: str,
password: str,
port: int = 27017,
testing: bool = False,
host: str = None,
hosts: list[str] = None,
replicaset: str = None,
) -> None:
"""
Connect to MongoDB.
@ -26,9 +32,15 @@ def connect(
port: Port
"""
global CLIENT, JARVISDB, CTC2DB, JARVIS_INST, CTC2_INST
CLIENT = AsyncIOMotorClient(
host=host, username=username, password=password, port=port, tz_aware=True, tzinfo=utc
)
if not replicaset:
CLIENT = AsyncIOMotorClient(
host=host, username=username, password=password, port=port, tz_aware=True, tzinfo=utc
)
else:
CLIENT = AsyncIOMotorClient(
hosts, username=username, password=password, tz_aware=True, tzinfo=utc, replicaset=replicaset
)
JARVISDB = CLIENT.narvis if testing else CLIENT.jarvis
CTC2DB = CLIENT.ctc2