Skip to content

Commit

Permalink
Merge pull request #6 from Sponsorlytix-Ltd/chore/mongo_client
Browse files Browse the repository at this point in the history
Chore/mongo client
  • Loading branch information
popmeup authored Nov 2, 2021
2 parents 7be1a1a + fd52e14 commit 12a0920
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
setup(
name='sponsorlytix_api_utils',
description='Sponsorlytix code utils',
version='1.1',
version='1.2',
author='Sponsorlytix Team',
install_requires=requirements,
setup_requires=['pytest-runner'],
Expand Down
16 changes: 6 additions & 10 deletions sponsorlytix_api_utils/sponsorlytix_mongo/client.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import os

from pymongo import MongoClient


class SponsorlytixMongoClient:

def __init__(self, mongodb_config, db_name='sponsorlytix'):
host, port = mongodb_config.get('host'), mongodb_config.get('port')
def __init__(self, host, port, db_name):
client = MongoClient(host, port)
self.client = client[db_name]
self.client = client.get_database(db_name)

def get_collection(self, collection_name):
return self.client[collection_name]
return self.client.get_collection(collection_name)

@classmethod
def get_client(cls, db_name='sponsorlytix'):
mongo_url = os.environ.get('MONGO_URL')
mongo_conn = MongoClient(mongo_url, 27017)
return mongo_conn[db_name]
def get_client(cls, host, port, db_name):
client = MongoClient(host, port)
return client.get_database(db_name)

0 comments on commit 12a0920

Please sign in to comment.