# -*- mode: shell-script -*-

include pretty

export DB_NAME="$SERVICE_NAME"                          ## general type of database (ie: postgres/mysql...)
export DB_DATADIR=/var/lib/mongodb

export DATA_DIR=$SERVICE_DATASTORE$DB_DATADIR


is_db_locked() {
    is_volume_used "$DATASTORE/${SERVICE_NAME}"
}


_set_server_db_params() {
    server_docker_opts+=("-v" "${SERVICE_CONFIGSTORE}/etc/mongod.conf:/etc/mongod.conf"
                         "--add-host" "${SERVICE_NAME}:127.0.0.1")
}

_set_db_params() {
    local docker_ip="$1" docker_network="$2"

    db_docker_opts+=("--network" "$docker_network")

    db_cmd_opts+=("--host" "$docker_ip")
    check_command="db.serverStatus().ok"
}

ddb () { dcmd mongo "$@"; }