#!/bin/bash

set -e

. ./STANDALONE-SERVER/_mongodb_standalone_common.bash

if "$GS_MONGODB_SHELL" \
    --quiet \
    --host "$GS_MONGODB_STANDALONE_CONNECT_HOST" \
    --port "$GS_MONGODB_PORT" \
    --eval 'quit(db.getSiblingDB("admin").runCommand({ping:1}).ok === 1 ? 0 : 1)' \
    >/dev/null 2>&1
then
    echo "MongoDB standalone server is available at $GS_MONGODB_STANDALONE_CONNECT_HOST:$GS_MONGODB_PORT."
else
    echo "MongoDB standalone server is not available at $GS_MONGODB_STANDALONE_CONNECT_HOST:$GS_MONGODB_PORT." >&2
    exit 1
fi
