Add support for replicated hosts
This commit is contained in:
parent
392797c4ae
commit
ec4219e5a5
1 changed files with 16 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue