Skip to content

Commit 528728f

Browse files
committed
🐛 add missing libmongo.sh fork
Issue: ZENKO-5302
1 parent eb0fc7d commit 528728f

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

  • solution-base/images/mongodb-sharded/debian-12/rootfs/opt/bitnami/scripts

solution-base/images/mongodb-sharded/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,3 +1667,46 @@ mongodb_execute_print_output() {
16671667
mongodb_execute() {
16681668
debug_execute mongodb_execute_print_output "$@"
16691669
}
1670+
1671+
# Copyright Broadcom, Inc. All Rights Reserved.
1672+
# SPDX-License-Identifier: APACHE-2.0
1673+
1674+
# shellcheck disable=SC2148
1675+
1676+
########################
1677+
# Execute an arbitrary query/queries against the running MongoDB service
1678+
# Stdin:
1679+
# Query/queries to execute
1680+
# Arguments:
1681+
# $1 - User to run queries
1682+
# $2 - Password
1683+
# $3 - Database where to run the queries
1684+
# $4 - Host (default to result of get_mongo_hostname function)
1685+
# $5 - Port (default $MONGODB_PORT_NUMBER)
1686+
# $6 - Extra arguments (default $MONGODB_SHELL_EXTRA_FLAGS)
1687+
# Returns:
1688+
# None
1689+
########################
1690+
mongodb_execute() {
1691+
local -r user="${1:-}"
1692+
local -r password="${2:-}"
1693+
local -r database="${3:-}"
1694+
local -r host="${4:-$(get_mongo_hostname)}"
1695+
local -r port="${5:-$MONGODB_PORT_NUMBER}"
1696+
local -r extra_args="${6:-$MONGODB_SHELL_EXTRA_FLAGS}"
1697+
local final_user="$user"
1698+
# If password is empty it means no auth, do not specify user
1699+
[[ -z "$password" ]] && final_user=""
1700+
1701+
local -a args=("--host" "$host" "--port" "$port")
1702+
[[ -n "$final_user" ]] && args+=("-u" "$final_user")
1703+
[[ -n "$password" ]] && args+=("-p" "$password")
1704+
if [[ -n "$extra_args" ]]; then
1705+
local extra_args_array=()
1706+
read -r -a extra_args_array <<<"$extra_args"
1707+
[[ "${#extra_args_array[@]}" -gt 0 ]] && args+=("${extra_args_array[@]}")
1708+
fi
1709+
[[ -n "$database" ]] && args+=("$database")
1710+
1711+
"$MONGODB_BIN_DIR/mongosh" "${args[@]}"
1712+
}

0 commit comments

Comments
 (0)