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(
|
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:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Connect to MongoDB.
|
Connect to MongoDB.
|
||||||
|
@ -26,9 +32,15 @@ def connect(
|
||||||
port: Port
|
port: Port
|
||||||
"""
|
"""
|
||||||
global CLIENT, JARVISDB, CTC2DB, JARVIS_INST, CTC2_INST
|
global CLIENT, JARVISDB, CTC2DB, JARVIS_INST, CTC2_INST
|
||||||
|
|
||||||
|
if not replicaset:
|
||||||
CLIENT = AsyncIOMotorClient(
|
CLIENT = AsyncIOMotorClient(
|
||||||
host=host, username=username, password=password, port=port, tz_aware=True, tzinfo=utc
|
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
|
JARVISDB = CLIENT.narvis if testing else CLIENT.jarvis
|
||||||
CTC2DB = CLIENT.ctc2
|
CTC2DB = CLIENT.ctc2
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue