def _is_mongo_running(
    db_host: str, db_port: int, db_name: str, connection_timeout_ms: int
) -> bool:
    """Connect to mongo with connection logic that mirrors the st2 code.

    In particular, this is based on st2common.models.db.db_setup().
    This should not import the st2 code as it should be self-contained.
    """
    # late import so that __file__ can be imported in the pants plugin without these imports
    import mongoengine
    from pymongo.errors import ConnectionFailure
    from pymongo.errors import ServerSelectionTimeoutError

    connection = mongoengine.connection.connect(
        db_name,
        host=db_host,
        port=db_port,
        connectTimeoutMS=connection_timeout_ms,
        serverSelectionTimeoutMS=connection_timeout_ms,
        uuidRepresentation="pythonLegacy",
    )

    # connection.connect() is lazy. Make a command to test the connection.
    try:
        # The ping command is cheap and does not require auth
        # https://www.mongodb.com/community/forums/t/how-to-use-the-new-hello-interface-for-availability/116748/
        connection.admin.command("ping")
    except (ConnectionFailure, ServerSelectionTimeoutError):
        return False
    return True
Connect to mongo with connection logic that mirrors the st2 code.

    In particular, this is based on st2common.models.db.db_setup().
    This should not import the st2 code as it should be self-contained.
    
pants-plugins/uses_services/scripts/is_mongo_running.py