diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index a3d0b80..0dd049f 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -5,21 +5,23 @@ # example: ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("wekan")' # example: ynh_mongo_eval_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # -# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--database=database] [--host=host] [--port=port] --command="command" -# | arg: -u, --user= - the user name to connect as -# | arg: -p, --password= - the user password -# | arg: -d, --database= - the database to connect to -# | arg: -h, --host= - the host to connect to -# | arg: -P, --port= - the port to connect to -# | arg: -c, --command= - the command to evaluate +# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" +# | arg: -u, --user= - the user name to connect as +# | arg: -p, --password= - the user password +# | arg: -d, --authenticationdatabase= - the authenticationdatabase to connect to +# | arg: -d, --database= - the database to connect to +# | arg: -h, --host= - the host to connect to +# | arg: -P, --port= - the port to connect to +# | arg: -c, --command= - the command to evaluate # # ynh_mongo_eval_as() { # Declare an array to define the options of this helper. - local legacy_args=updhPc - local -A args_array=( [u]=user= [p]=password= [d]=database= [h]=host= [P]=port= [c]=command= ) + local legacy_args=upadhPc + local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= ) local user local password + local authenticationdatabase local database local host local port @@ -28,7 +30,8 @@ ynh_mongo_eval_as() { ynh_handle_getopts_args "$@" user="${user:-}" password="${password:-}" - database="${database:-}" + authenticationdatabase="${authenticationdatabase:-"admin"}" + database="${database:-"admin"}" host="${host:-}" port="${port:-}" @@ -36,23 +39,16 @@ ynh_mongo_eval_as() { if [ -n "$user" ] then user="--username=$user" - - # If password is provided - if [ -n "$password" ] - then - password="--password=$password" - fi - - # If database is provided - if [ -n "$database" ] - then - database="--authenticationDatabase=$database" - fi + password="--password=$password" + authenticationdatabase="--authenticationDatabase=$authenticationdatabase" else password="" - database="" + authenticationdatabase="" fi + # Configure dabase connection + database="use $database" + # If host is provided if [ -n "$host" ] then @@ -65,24 +61,25 @@ ynh_mongo_eval_as() { port="--port=$port" fi - mongo --quiet $user $password $database $host $port --eval="$command" + mongo --quiet $user $password $authenticationdatabase $host $port <