Skip to content

Commit

Permalink
Merge pull request #203 from labmlai/readme-updates
Browse files Browse the repository at this point in the history
raise error if not mongodb connection found
  • Loading branch information
hnipun committed Apr 4, 2024
2 parents 1c1a373 + 1a59a9c commit 8c82a18
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/server/labml_app/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,23 @@ def msave_dict(self, keys: List[str], data: List[ModelDict]):
computer.ComputerIndex] + [m for s, m, p in analyses.AnalysisManager.get_db_indexes()]


def init_mongo_db(mongo_address: str = ''):
def init_mongo_db(mongo_address: str = '', port: int = 27017):
if not mongo_address:
if 'MONGO_HOST' in os.environ:
mongo_address = os.getenv('MONGO_HOST')
else:
mongo_address = 'localhost'

mongo_client = MongoClient(host=mongo_address, port=27017, connect=False)
mongo_client = MongoClient(host=mongo_address, port=port, connect=False)

try:
mongo_client.admin.command('ismaster')
except ConnectionFailure:
raise Exception('MongoDB is not installed or not started. Please follow the tutorial here for more info, '
'https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/')
raise Exception(
f'MongoDB is either not installed or not running on the {mongo_address} at port {port}. '
'For detailed instructions on installation, please refer to the tutorial available at '
'https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/.'
)

db = mongo_client['labml']

Expand Down

0 comments on commit 8c82a18

Please sign in to comment.