#!/usr/bin/env python3

import os
import time
import pymongo

mongo_uri = os.getenv('MONGO_URI', 'mongodb://mongodb:27017')

while True:
    try:
        client = pymongo.MongoClient(mongo_uri, connectTimeoutMS=1000, socketTimeoutMS=1000, serverSelectionTimeoutMS=1000)
        result = client.admin.command('ismaster')
        print(result)
        exit(0)
    except Exception as error:
        print('Error:', error.__class__.__name__, error)
    time.sleep(2)
