mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-22 00:14:01 +02:00
style: Refactoring imports, adapting MongoConnector to different connection_strings
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from abc import ABC
|
||||
|
||||
from models.News import News
|
||||
from News.models.News import News
|
||||
|
||||
|
||||
class NewsServiceInterface(ABC):
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pymongo
|
||||
from models.News import News
|
||||
from utils.NewsServiceInterface import NewsServiceInterface
|
||||
from News.models.News import News
|
||||
from News.utils.NewsServiceInterface import NewsServiceInterface
|
||||
|
||||
|
||||
class MongoConnector:
|
||||
@ -8,7 +8,7 @@ class MongoConnector:
|
||||
self,
|
||||
hostname,
|
||||
database: str,
|
||||
port: int = 27017,
|
||||
port: int | None,
|
||||
username: str | None = None,
|
||||
password: str | None = None,
|
||||
):
|
||||
@ -20,10 +20,13 @@ class MongoConnector:
|
||||
|
||||
def connect(self, hostname, port, username, password) -> pymongo.MongoClient:
|
||||
if username is not None and password is not None:
|
||||
connection_string = f"mongodb://{username}:{password}@{hostname}:{port}"
|
||||
connection_string = f"mongodb+srv://{username}:{password}@{hostname}"
|
||||
else:
|
||||
connection_string = f"mongodb://{hostname}:{port}"
|
||||
|
||||
connection_string = f"mongodb+srv://{hostname}"
|
||||
if port is not None:
|
||||
connection_string += f":{port}"
|
||||
connection_string = connection_string.replace("mongodb+srv", "mongodb")
|
||||
print(connection_string)
|
||||
return pymongo.MongoClient(connection_string)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user