import pymongo

MONGO_DB_HOST = '143.205.173.36'
MONGO_DB_PORT = '30003'

class MongoRepository:
    # TODO extract to docker env var
    _username = 'root'
    _password = 'root'
    _collection : pymongo.collection.Collection = None

    def __init__(self, username=_username, password=_password):
        myclient = pymongo.MongoClient(f"mongodb://{username}:{password}@{MONGO_DB_HOST}:{MONGO_DB_PORT}/")
        database = myclient['traceRetrievalDB'] # trace retrieval
        self._collection = database['traces']

    def insert_trace(self, content: dict):
        self._collection.insert_one(content)

    def get_traces(self, selection: dict = {}):
        return self._collection.find(selection)

    def drop_collection(self):
        self._collection.drop()

traces = MongoRepository().get_traces()
for t in traces:
    print(str(t))

# MongoRepository().drop_collection()