from pymongo import MongoClient

MONGODB_URI = "mongodb://root:3wwfoUjyk2E2zWELXFlLuHqfw1ALlOp4pb2H5Vq3TImbMIHL2h1u8Jej2mjzCPl@docdb.connorrhodes.com:35563"


def get_client():
    return MongoClient(MONGODB_URI)


def get_db(db_name):
    return MongoClient(MONGODB_URI)[db_name]


def get_collection(db_name, collection_name):
    return MongoClient(MONGODB_URI)[db_name][collection_name]


def list_databases():
    client = get_client()
    for db_name in client.list_database_names():
        db = client[db_name]
        collections = []
        for coll_name in db.list_collection_names():
            count = db[coll_name].estimated_document_count()
            collections.append(f"{coll_name} ({count} docs)")
        print(f"Database: {db_name}")
        for c in collections:
            print(f"  {c}")
    client.close()


if __name__ == "__main__":
    list_databases()
