From 9acadebd3f0407cedc3a9d49453cf422b08dc37f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:06:36 +0000 Subject: [PATCH 01/13] Initial plan From 5ba44c80ed0a3f7af21392971459c9924714eca1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:14:11 +0000 Subject: [PATCH 02/13] Add MongoDB Shell (mongosh) installation support Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com> --- README.md | 36 +++++++- bin/m | 242 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 273 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 593c3ff..e8463bf 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,34 @@ Use or download a specific version of the Database Tools: $ m tools 100.9.4 ``` +### Downloading MongoDB Shell + +The MongoDB Shell (mongosh) is released separately from the server. You can use `m` to manage your MongoDB Shell version independently of your MongoDB server and tools versions. + +List available MongoDB Shell versions: + +```bash +$ m shell ls +``` + +List installed MongoDB Shell versions: + +```bash +$ m shell installed +``` + +Use or download the latest stable release of the MongoDB Shell: + +```bash +$ m shell stable +``` + +Use or download a specific version of the MongoDB Shell: + +```bash +$ m shell 2.3.7 +``` + ### Removing Binaries Remove some previously installed versions: @@ -238,7 +266,7 @@ Output from `m --help`: m --legacy Install generic Linux version (does not include SSL) m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] - m shell [args ...] Open a mongo shell with [args ...] + m s [args ...] Open a mongo shell with [args ...] m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available @@ -259,6 +287,10 @@ Output from `m --help`: m tools X.Y.Z Install or activate the Database Tools X.Y.Z m tools ls Output the versions of the Database Tools available m tools installed [--json] Output installed versions of the Database Tools available + m shell stable Install or activate the latest stable MongoDB Shell release + m shell X.Y.Z Install or activate the MongoDB Shell X.Y.Z + m shell ls Output the versions of the MongoDB Shell available + m shell installed [--json] Output installed versions of the MongoDB Shell available Events: @@ -274,7 +306,7 @@ Output from `m --help`: installed lls shard sd, mongos - shell s, sh, mongo + mongo s, sh list ls, available, avail use as, mongod which bin diff --git a/bin/m b/bin/m index b4fb5d3..a559544 100755 --- a/bin/m +++ b/bin/m @@ -20,6 +20,9 @@ VERSIONS_DIR=$M_DIR/versions # Directory for MongoDB Tools version binaries TOOLS_DIR=$M_DIR/tools/versions +# Directory for MongoDB Shell version binaries +SHELL_DIR=$M_DIR/shell/versions + # Working directory for unpacking MongoDB tarballs BUILD_DIR_BASE=$M_DIR/mongo- @@ -133,7 +136,7 @@ display_help() { m --legacy Install generic Linux version (does not include SSL) m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] - m shell [args ...] Open a mongo shell with [args ...] + m s [args ...] Open a mongo shell with [args ...] m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available @@ -154,6 +157,10 @@ display_help() { m tools X.Y.Z Install or activate the Database Tools X.Y.Z m tools ls Output the versions of the Database Tools available m tools installed [--json] Output installed versions of the Database Tools available + m shell stable Install or activate the latest stable MongoDB Shell release + m shell X.Y.Z Install or activate the MongoDB Shell X.Y.Z + m shell ls Output the versions of the MongoDB Shell available + m shell installed [--json] Output installed versions of the MongoDB Shell available Events: @@ -169,7 +176,7 @@ display_help() { installed lls shard sd, mongos - shell s, sh, mongo + mongo s, sh list ls, available, avail use as, mongod which bin @@ -576,6 +583,223 @@ display_tools_versions() { fi } +# +# Find the current installed version of shell. +# + +check_current_shell_version() { + which $M_BIN_DIR/mongosh &> /dev/null + if test $? -eq 0; then + active_shell=`$M_BIN_DIR/mongosh --version | sed -nE "s/^([0-9]+\.[0-9]+\.[0-9]+)$/\1/p" | head -1` + fi +} + +# +# Find all available versions of the MongoDB Shell. +# + +get_all_shell_versions() { + local rc_regex="" + if [[ $1 == "--rc" ]]; then + rc_regex="(-rc[0-9]+)?" + fi + + curl_shell_versions=(curl -sSf -H "Accept: application/vnd.github.v3+json") + if [ -n "${GH_TOKEN:-}" ]; then + debug "Using GitHub token from environment for API requests" + curl_shell_versions+=(-H "authorization: bearer ${GH_TOKEN:?}") + fi + curl_shell_versions+=("https://api.github.com/repos/mongodb-js/mongosh/git/refs/tags") + + shell_versions="$("${curl_shell_versions[@]}" \ + | sed -nE "s/^.*\"ref\"\: \"refs\/tags\/v([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$rc_regex)\",$/\1/p" \ + | sort -V)" + + versions="$shell_versions" +} + +# +# Output all MongoDB Shell versions +# + +list_shell_versions() { + check_current_shell_version + + if [[ $2 == "--rc" ]]; then + local rc="--rc" + fi + + get_all_shell_versions $rc + + for v in $versions; do + if test "$active_shell" = "$v"; then + printf " $v\n" + else + if test -d $SHELL_DIR/$v; then + printf " * $v\n" + else + printf " $v\n" + fi + fi + done +} + +# +# Output all installed shell versions. +# Pass "--json" to output in JSON format. +# + +display_shell_versions() { + local option=$1; shift + local json=false + if test "$option" = "--json"; then + json=true + fi + + declare -a versions + if [ -e $SHELL_DIR ]; then + versions=(`ls -1 $SHELL_DIR | sort -t. -k 1,1n -k 2,2n -k 3,3n`) + fi + + if test -z "$versions"; then + if $json; then + echo "[]" + else + echo "No installed versions" + fi + return + fi + local last=${versions[${#versions[@]}-1]} + + if $json; then + printf "[" + fi + + check_current_shell_version + for version in ${versions[@]}; do + local dir="$SHELL_DIR/$version" + local config=`test -f "$dir"/.config && cat "$dir"/.config` + if $json; then + printf "\n {\n \"name\" : \"$version\",\n \"path\" : \"$dir/bin/\" \n }" + if [ "$version" != "$last" ]; then + printf "," + fi + else + if [ "$version" = "$active_shell" ]; then + printf " $version $config\n" + else + printf " $version $config\n" + fi + fi + done + + if $json; then + printf "\n]\n" + fi +} + +# +# Install MongoDB Shell binaries for provided version +# +# install_shell_bin +# + +install_shell_bin() { + local version=$1 + + log "installing binary" + + ext="tgz" + get_distro_and_arch + + if [[ $os = "linux" ]]; then + dist="linux" + fi + + if [[ $os = "osx" ]]; then + dist="macos" + if vergte $version "2.0.0"; then + ext="zip" + fi + fi + + printf "Downloading from https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext" + + if [[ $ext = "zip" ]]; then + curl -sSLf https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext -o $M_DIR/shell-$version.$ext + else + curl -sSLf https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext -o $M_DIR/shell-$version.$ext + fi + + if test $? -gt 0; then + printf "Error: shell installation failed\n" + printf " Tarball fetch for MongoDB Shell version $version failed.\n" + printf " Try a different version.\n" + exit 1 + fi + + mkdir -p $SHELL_DIR/$version/bin + + if [[ $ext = "zip" ]]; then + unzip -q $M_DIR/shell-$version.zip -d $M_DIR + mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh $SHELL_DIR/$version/bin/ + mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh_crypt_v1.* $SHELL_DIR/$version/bin/ 2>/dev/null || true + rm -r $M_DIR/mongosh-$version-$dist-$arch + else + tar -xzf $M_DIR/shell-$version.tgz -C $M_DIR + mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh $SHELL_DIR/$version/bin/ + mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh_crypt_v1.* $SHELL_DIR/$version/bin/ 2>/dev/null || true + rm -r $M_DIR/mongosh-$version-$dist-$arch + fi + + log "removing source" + rm $M_DIR/shell-$version.$ext + log "Installation complete" +} + +# +# Install and activate MongoDB Shell. +# +# install_shell +# + +install_shell() { + local version=$1 + + check_current_shell_version + check_current_version + + if [[ $version == $active_shell ]]; then + printf "Already Active: MongoDB Server $active, MongoDB Shell $active_shell\n" + exit 0 + fi + + if [[ $version =~ "rc" ]]; then + local rc="--rc" + fi + get_all_shell_versions $rc + + if [[ $version == "stable" ]]; then + # Set version to the latest available version + version=`echo $versions | awk 'NF>1{print $NF}'` + fi + + if [[ ! $versions =~ $version ]]; then + printf "Could not find any releases for the requested version "$version" of MongoDB Shell\n" + exit 1; + fi + + local dir=$SHELL_DIR/$version + if test ! -d $dir; then + prompt_install "MongoDB Shell version $version is not installed." + install_shell_bin $version + fi + + printf "\nActivating: MongoDB Server $active, MongoDB Shell $version\n" + debug "Shell path: $dir" + ln -fs $dir/bin/* $M_BIN_DIR +} + # # Install MongoDB [config ...] # @@ -1541,6 +1765,17 @@ handle_tools() { esac } +# Handle shell commands + +handle_shell() { + case $1 in + ls|list|available|avail) list_shell_versions $@; exit;; + lls|installed) display_shell_versions $2; exit ;; + stable) install_shell $@; exit ;; + *) install_shell $@; exit ;; + esac +} + # Handle arguments if test $# -eq 0; then @@ -1556,7 +1791,7 @@ else bin|which) display_bin_path_for_version $2; exit ;; as|use|mongod) shift; execute_with_version $@; exit ;; sd|shard|mongos) shift; execute_shard_with_version $@; exit ;; - s|sh|shell|mongo) shift; execute_shell_with_version $@; exit ;; + s|sh|mongo) shift; execute_shell_with_version $@; exit ;; rm) shift; remove_versions $@; exit ;; latest) install_mongo `$0 --latest`; exit ;; stable) install_mongo `$0 --stable`; exit ;; @@ -1567,6 +1802,7 @@ else install) shift; install_mongo $@; exit ;; reinstall) shift; CONFIRM=0; remove_versions $@; install_mongo $@; exit;; tools) shift; handle_tools $@; exit;; + shell) shift; handle_shell $@; exit;; *) install_mongo $@; exit ;; esac shift From a66e2a0deb9b5c57521c995fca589a69582259ca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:17:48 +0000 Subject: [PATCH 03/13] Fix display formatting for active shell version and improve version validation Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com> --- bin/m | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/bin/m b/bin/m index a559544..b335a0d 100755 --- a/bin/m +++ b/bin/m @@ -686,7 +686,7 @@ display_shell_versions() { fi else if [ "$version" = "$active_shell" ]; then - printf " $version $config\n" + printf " * $version $config\n" else printf " $version $config\n" fi @@ -777,16 +777,27 @@ install_shell() { if [[ $version =~ "rc" ]]; then local rc="--rc" fi - get_all_shell_versions $rc - + if [[ $version == "stable" ]]; then + # Need to fetch versions to find the latest + get_all_shell_versions $rc + if [[ -z "$versions" ]]; then + printf "Could not fetch available versions of MongoDB Shell\n" + exit 1 + fi # Set version to the latest available version version=`echo $versions | awk 'NF>1{print $NF}'` - fi - - if [[ ! $versions =~ $version ]]; then - printf "Could not find any releases for the requested version "$version" of MongoDB Shell\n" - exit 1; + elif [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + # Specific version provided, try to install it directly + # (only validate if we successfully fetched versions) + get_all_shell_versions $rc + if [[ ! -z "$versions" ]] && [[ ! $versions =~ $version ]]; then + printf "Could not find any releases for the requested version "$version" of MongoDB Shell\n" + exit 1 + fi + else + printf "Invalid version format: $version\n" + exit 1 fi local dir=$SHELL_DIR/$version From 60a5937e5723465b01aeccf8b956c2b526361e55 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:20:03 +0000 Subject: [PATCH 04/13] Add backward compatibility for shell execution command Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com> --- README.md | 3 +++ bin/m | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e8463bf..ad44fa6 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,8 @@ Use or download a specific version of the MongoDB Shell: $ m shell 2.3.7 ``` +**Note:** The `m shell ` command without additional arguments will install/activate the specified mongosh version. For backward compatibility, `m shell [args...]` with additional arguments will execute the legacy `mongo` shell from the specified MongoDB server version. To execute a mongo shell without ambiguity, use the `m s [args...]` alias instead. + ### Removing Binaries Remove some previously installed versions: @@ -267,6 +269,7 @@ Output from `m --help`: m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] m s [args ...] Open a mongo shell with [args ...] + m shell [args ...] Open a mongo shell with [args ...] (legacy) m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available diff --git a/bin/m b/bin/m index b335a0d..a5481d0 100755 --- a/bin/m +++ b/bin/m @@ -137,6 +137,7 @@ display_help() { m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] m s [args ...] Open a mongo shell with [args ...] + m shell [args ...] Open a mongo shell with [args ...] (legacy) m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available @@ -1779,12 +1780,40 @@ handle_tools() { # Handle shell commands handle_shell() { - case $1 in - ls|list|available|avail) list_shell_versions $@; exit;; - lls|installed) display_shell_versions $2; exit ;; - stable) install_shell $@; exit ;; - *) install_shell $@; exit ;; - esac + # For backward compatibility, check if this is shell execution + # Shell execution: m shell + # Shell installation: m shell + + local first_arg="$1" + local second_arg="$2" + + # Known installation subcommands + case "$first_arg" in + ls|list|available|avail) + list_shell_versions $@ + exit + ;; + lls|installed) + display_shell_versions "$second_arg" + exit + ;; + stable) + install_shell $@ + exit + ;; + *) + # Check if there are additional args beyond the version + # If yes, it's shell execution (backward compat) + if [[ -n "$second_arg" ]]; then + execute_shell_with_version $@ + exit + else + # No additional args, treat as installation + install_shell $@ + exit + fi + ;; + esac } # Handle arguments From 523717c85c723d2c86869158e3dfac50478be827 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:22:48 +0000 Subject: [PATCH 05/13] Remove backward compatibility to keep shell command clear and simple Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com> --- README.md | 3 +-- bin/m | 41 ++++++----------------------------------- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index ad44fa6..f03c026 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ Use or download a specific version of the MongoDB Shell: $ m shell 2.3.7 ``` -**Note:** The `m shell ` command without additional arguments will install/activate the specified mongosh version. For backward compatibility, `m shell [args...]` with additional arguments will execute the legacy `mongo` shell from the specified MongoDB server version. To execute a mongo shell without ambiguity, use the `m s [args...]` alias instead. +**Note:** To execute the legacy `mongo` shell from a specific MongoDB server version, use `m s [args...]` or `m mongo [args...]` instead. ### Removing Binaries @@ -269,7 +269,6 @@ Output from `m --help`: m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] m s [args ...] Open a mongo shell with [args ...] - m shell [args ...] Open a mongo shell with [args ...] (legacy) m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available diff --git a/bin/m b/bin/m index a5481d0..b335a0d 100755 --- a/bin/m +++ b/bin/m @@ -137,7 +137,6 @@ display_help() { m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] m s [args ...] Open a mongo shell with [args ...] - m shell [args ...] Open a mongo shell with [args ...] (legacy) m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available @@ -1780,40 +1779,12 @@ handle_tools() { # Handle shell commands handle_shell() { - # For backward compatibility, check if this is shell execution - # Shell execution: m shell - # Shell installation: m shell - - local first_arg="$1" - local second_arg="$2" - - # Known installation subcommands - case "$first_arg" in - ls|list|available|avail) - list_shell_versions $@ - exit - ;; - lls|installed) - display_shell_versions "$second_arg" - exit - ;; - stable) - install_shell $@ - exit - ;; - *) - # Check if there are additional args beyond the version - # If yes, it's shell execution (backward compat) - if [[ -n "$second_arg" ]]; then - execute_shell_with_version $@ - exit - else - # No additional args, treat as installation - install_shell $@ - exit - fi - ;; - esac + case $1 in + ls|list|available|avail) list_shell_versions $@; exit;; + lls|installed) display_shell_versions $2; exit ;; + stable) install_shell $@; exit ;; + *) install_shell $@; exit ;; + esac } # Handle arguments From 9842bec787503af3e7dad131931dabe292438beb Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 14:29:58 -0700 Subject: [PATCH 06/13] chore: fix shell installation --- bin/m | 118 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 60 deletions(-) diff --git a/bin/m b/bin/m index b335a0d..ad844df 100755 --- a/bin/m +++ b/bin/m @@ -374,19 +374,18 @@ install_tools_bin() { log "installing binary" ext="tgz" - get_distro_and_arch + get_distro_and_arch 'tools' if [[ $os = "linux" ]]; then # for linux fetch the rhel7 tarball by default local dist=rhel70 # shadowing earlier $distro for distro in $distros; do - if good "https://fastdl.mongodb.org/tools/db/mongodb-database-tools-$distro-$arch-$version.tgz"; then + if good "https://fastdl.mongodb.org/tools/db/mongodb-database-tools-$distro-$arch-$version.$ext"; then dist=$distro break fi done - fi - if [[ $os = "osx" ]]; then + elif [[ $os = "osx" ]]; then dist="macos" if vergte $version "100.1.0"; then ext="zip" @@ -408,7 +407,7 @@ install_tools_bin() { $GET https://fastdl.mongodb.org/tools/db/mongodb-database-tools-$dist-$arch-$version.$ext -o $M_DIR/tools-$version.$ext if test $? -gt 0; then printf "Error: tools installation failed\n" - printf " Tarball fetch for MongoDB tools version $version failed.\n" + printf " Fetch for MongoDB tools version $version failed.\n" printf " Try a different version or view $logpath to view\n" printf " error details.\n" exit 1 @@ -633,7 +632,7 @@ list_shell_versions() { for v in $versions; do if test "$active_shell" = "$v"; then - printf " $v\n" + printf " ο $v\n" else if test -d $SHELL_DIR/$v; then printf " * $v\n" @@ -707,54 +706,52 @@ display_shell_versions() { install_shell_bin() { local version=$1 - log "installing binary" + log "installing mongosh $version" ext="tgz" - get_distro_and_arch - + get_distro_and_arch 'shell' + if [[ $os = "linux" ]]; then dist="linux" fi - + if [[ $os = "osx" ]]; then - dist="macos" - if vergte $version "2.0.0"; then - ext="zip" - fi + dist="darwin" + ext="zip" fi - printf "Downloading from https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext" + link="https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext" + + log "downloading $link" + $GET "$link" -o $M_DIR/mongosh-$version.$ext - if [[ $ext = "zip" ]]; then - curl -sSLf https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext -o $M_DIR/shell-$version.$ext - else - curl -sSLf https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext -o $M_DIR/shell-$version.$ext - fi - if test $? -gt 0; then - printf "Error: shell installation failed\n" - printf " Tarball fetch for MongoDB Shell version $version failed.\n" - printf " Try a different version.\n" + printf "Error: mongosh installation failed\n" + printf " Fetch for MongoDB Shell version $version failed.\n" + printf " Try a different version or view $logpath to view\n" + printf " error details.\n" + printf "\n" + printf "You might also consider installing the MongoDB shell from the MongoDB Download Center:\n" + printf " https://www.mongodb.com/try/download/shell\n" exit 1 fi - - mkdir -p $SHELL_DIR/$version/bin - + + mkdir -p $SHELL_DIR/$version + + log "unpacking source" if [[ $ext = "zip" ]]; then - unzip -q $M_DIR/shell-$version.zip -d $M_DIR - mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh $SHELL_DIR/$version/bin/ - mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh_crypt_v1.* $SHELL_DIR/$version/bin/ 2>/dev/null || true - rm -r $M_DIR/mongosh-$version-$dist-$arch + unzip -q $M_DIR/mongosh-$version.zip -d $SHELL_DIR/$version else - tar -xzf $M_DIR/shell-$version.tgz -C $M_DIR - mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh $SHELL_DIR/$version/bin/ - mv $M_DIR/mongosh-$version-$dist-$arch/bin/mongosh_crypt_v1.* $SHELL_DIR/$version/bin/ 2>/dev/null || true - rm -r $M_DIR/mongosh-$version-$dist-$arch + tar -xzf $M_DIR/mongosh-$version.tgz -C $SHELL_DIR/$version fi - - log "removing source" - rm $M_DIR/shell-$version.$ext - log "Installation complete" + + + log "moving files" + mv $SHELL_DIR/$version/mongosh-$version-$dist-$arch/* $SHELL_DIR/$version + + log "cleaning up" + rm $M_DIR/mongosh-$version.$ext + rm -r $SHELL_DIR/$version/mongosh-$version-$dist-$arch } # @@ -777,7 +774,7 @@ install_shell() { if [[ $version =~ "rc" ]]; then local rc="--rc" fi - + if [[ $version == "stable" ]]; then # Need to fetch versions to find the latest get_all_shell_versions $rc @@ -805,10 +802,12 @@ install_shell() { prompt_install "MongoDB Shell version $version is not installed." install_shell_bin $version fi - - printf "\nActivating: MongoDB Server $active, MongoDB Shell $version\n" + + log "activating MongoDB Shell $version" debug "Shell path: $dir" ln -fs $dir/bin/* $M_BIN_DIR + + printf "Installation complete: MongoDB Shell $version activated!\n" } # @@ -816,7 +815,6 @@ install_shell() { # install_mongo() { - local version=$1; shift local config=$@ local rc="" @@ -919,29 +917,19 @@ install_mongo() { if vergte $version "6.0.0"; then if ! command -v mongosh &> /dev/null; then echo "" - echo "NOTE: the legacy mongo shell is not included in MongoDB 6.0+ distributions" + echo "NOTE: the mongo shell is not included in MongoDB 6.0+ distributions." + echo "" + echo "Install and use the MongoDB Shell (mongosh) separately via:" + echo " m shell stable" echo "" - echo "Download the new MongoDB Shell (mongosh):" + echo "Or download it directly from the MongoDB website:" echo " https://www.mongodb.com/try/download/shell" echo "" - - # Convenience for macOS users - if [[ "$(uname)" == "Darwin" ]]; then - if command -v brew &> /dev/null; then - prompt_install "Install "mongosh" via brew?" - brew install mongosh --quiet - else - echo "Install via brew:" - echo " brew install mongosh" - fi - echo "" - fi fi fi } -# # Prompt installation # # prompt_install "About to install something" @@ -1006,7 +994,7 @@ install_bin() { fi # determine url based on os and arch - get_distro_and_arch + get_distro_and_arch 'server' # determine the download url if [[ "$community" == 1 ]]; then @@ -1083,6 +1071,16 @@ install_bin() { # get_distro_and_arch() { + local type= + case "$1" in + tools|server|shell) + type="$1" + ;; + *) + abort "Invalid type: '$1' (expected: tools, server, or shell)" + ;; + esac + arch=`uname -m` local OS=`uname` os=`echo $OS | tr '[:upper:]' '[:lower:]'` @@ -1092,7 +1090,7 @@ get_distro_and_arch() { os=linux ;; darwin* ) os=osx - if [ "$arch" = "arm64" ]; then + if [[ "$type" == "server" ]] && [ "$arch" = "arm64" ]; then if [ $(numeric_version $version) -lt $(numeric_version "6.0.0") ]; then echo "" echo "NOTE: Apple Silicon is not natively supported for MongoDB server before 6.0" From 2d672d36b40316a3239022b3fb8bd80db3af49aa Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 14:44:34 -0700 Subject: [PATCH 07/13] fix: ux when no version passed --- bin/m | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/bin/m b/bin/m index ad844df..99cb2fb 100755 --- a/bin/m +++ b/bin/m @@ -1766,23 +1766,31 @@ list_posts() { # Handle tools commands handle_tools() { - case $1 in - ls|list|available|avail) list_tools_versions $@; exit;; - lls|installed) display_tools_versions $2; exit ;; - stable) install_tools $@; exit ;; - *) install_tools $@; exit ;; - esac + if test $# -eq 0; then + display_tools_versions + else + case $1 in + ls|list|available|avail) list_tools_versions $@; exit;; + lls|installed) display_tools_versions $2; exit ;; + stable) install_tools $@; exit ;; + *) install_tools $@; exit ;; + esac + fi } # Handle shell commands handle_shell() { - case $1 in - ls|list|available|avail) list_shell_versions $@; exit;; - lls|installed) display_shell_versions $2; exit ;; - stable) install_shell $@; exit ;; - *) install_shell $@; exit ;; - esac + if test $# -eq 0; then + display_shell_versions + else + case $1 in + ls|list|available|avail) list_shell_versions $@; exit;; + lls|installed) display_shell_versions $2; exit ;; + stable) install_shell $@; exit ;; + *) install_shell $@; exit ;; + esac + fi } # Handle arguments From f2d7fe4eae034f3e2d5715543c71167f269a4be7 Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 15:05:31 -0700 Subject: [PATCH 08/13] feat: consistent ls output --- bin/m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/m b/bin/m index 99cb2fb..8a5b1f1 100755 --- a/bin/m +++ b/bin/m @@ -279,7 +279,7 @@ display_versions() { fi else if [ "$version" = "$active" ]; then - printf " * $version $config\n" + printf " ✔ $version $config\n" else printf " $version $config\n" fi @@ -488,7 +488,7 @@ list_tools_versions() { for v in $versions; do if test "$active_tools" = "$v"; then - printf " $v\n" + printf " ✔ $v\n" else if test -d $VERSIONS_DIR/$v || test -d $TOOLS_DIR/$v; then printf " * $v\n" @@ -570,7 +570,7 @@ display_tools_versions() { fi else if [ "$version" = "$active_tools" ]; then - printf " $version $config\n" + printf " ✔ $version $config\n" else printf " $version $config\n" fi @@ -632,7 +632,7 @@ list_shell_versions() { for v in $versions; do if test "$active_shell" = "$v"; then - printf " ο $v\n" + printf " ✔ $v\n" else if test -d $SHELL_DIR/$v; then printf " * $v\n" @@ -685,7 +685,7 @@ display_shell_versions() { fi else if [ "$version" = "$active_shell" ]; then - printf " * $version $config\n" + printf " ✔ $version $config\n" else printf " $version $config\n" fi @@ -1609,7 +1609,7 @@ list_versions() { for v in $versions; do if test "$active" = "$v"; then - printf " ο $v\n" + printf " ✔ $v\n" else if test -d $VERSIONS_DIR/$v; then printf " * $v\n" From 2cb6361ba88333620245cc1a00be59c95ae21fe3 Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 15:22:22 -0700 Subject: [PATCH 09/13] feat: rm shell and tools versions --- bin/m | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/bin/m b/bin/m index 8a5b1f1..536c8d1 100755 --- a/bin/m +++ b/bin/m @@ -156,10 +156,12 @@ display_help() { m tools stable Install or activate the latest stable Database Tools release m tools X.Y.Z Install or activate the Database Tools X.Y.Z m tools ls Output the versions of the Database Tools available + m tools rm Remove the given Database Tools versions m tools installed [--json] Output installed versions of the Database Tools available m shell stable Install or activate the latest stable MongoDB Shell release m shell X.Y.Z Install or activate the MongoDB Shell X.Y.Z m shell ls Output the versions of the MongoDB Shell available + m shell rm Remove the given MongoDB Shell versions m shell installed [--json] Output installed versions of the MongoDB Shell available Events: @@ -582,6 +584,46 @@ display_tools_versions() { fi } +remove_tools_versions() { + test -z $1 && abort "version(s) required" + check_current_tools_version + + while test $# -ne 0; do + local version=${1#v} + local rmpath="$TOOLS_DIR/$version" + debug "=> Path: $rmpath" + + if verlte $version "4.3.2"; then + printf "Error: Cannot remove tools version $version since it is included with the\n" + printf "MongoDB server package. To remove this version, remove the server instead:\n" + printf " m rm $version\n" + shift + continue + fi + + if test "$version" = "$active_tools"; then + printf "WARNING: $version is the active version!\n" + if [[ "$CONFIRM" == 1 ]]; then + read -p "Are you sure you want to remove this? [y/N] " yn + case $yn in + [Yy]* ) ;; + * ) printf "SKIPPING $version "; exit;; + esac + fi + fi + + if [ -d $rmpath ]; then + rm -rf $rmpath + echo "Removed MongoDB tools version $version" + active_tools="" + else + echo "MongoDB tools version $version is not installed" + fi + + shift + done +} + # # Find the current installed version of shell. # @@ -697,6 +739,37 @@ display_shell_versions() { fi } +remove_shell_versions() { + test -z $1 && abort "version(s) required" + check_current_shell_version + + while test $# -ne 0; do + local version=${1#v} + local rmpath="$SHELL_DIR/$version" + debug "=> Path: $rmpath" + if test "$version" = "$active_shell"; then + printf "WARNING: $version is the active version!\n" + if [[ "$CONFIRM" == 1 ]]; then + read -p "Are you sure you want to remove this? [y/N] " yn + case $yn in + [Yy]* ) ;; + * ) printf "SKIPPING $version "; exit;; + esac + fi + fi + + if [ -d $rmpath ]; then + rm -rf $rmpath + echo "Removed MongoDB shell version $version" + active_shell="" + else + echo "MongoDB shell version $version is not installed" + fi + + shift + done +} + # # Install MongoDB Shell binaries for provided version # @@ -1773,6 +1846,7 @@ handle_tools() { ls|list|available|avail) list_tools_versions $@; exit;; lls|installed) display_tools_versions $2; exit ;; stable) install_tools $@; exit ;; + rm) shift; remove_tools_versions $@; exit ;; *) install_tools $@; exit ;; esac fi @@ -1788,6 +1862,7 @@ handle_shell() { ls|list|available|avail) list_shell_versions $@; exit;; lls|installed) display_shell_versions $2; exit ;; stable) install_shell $@; exit ;; + rm) shift; remove_shell_versions $@; exit ;; *) install_shell $@; exit ;; esac fi From 6ac551715ecdb3518435213007973026b00d6953 Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 16:18:12 -0700 Subject: [PATCH 10/13] fix: backward compat with m shell --- bin/m | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/bin/m b/bin/m index 536c8d1..399d656 100755 --- a/bin/m +++ b/bin/m @@ -84,6 +84,14 @@ abort_not_installed() { exit 1 } +abort_shell_not_installed() { + printf "Error: The requested MongoDB shell version is not installed.\n" + if [[ ! -z "$version" ]]; then + printf "Try 'm mongosh $version' to download and activate.\n" + fi + exit 1 +} + # # Check file age (in seconds) # @@ -136,7 +144,7 @@ display_help() { m --legacy Install generic Linux version (does not include SSL) m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] - m s [args ...] Open a mongo shell with [args ...] + m shell [args ...] Open a mongo shell with [args ...] m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available @@ -157,17 +165,17 @@ display_help() { m tools X.Y.Z Install or activate the Database Tools X.Y.Z m tools ls Output the versions of the Database Tools available m tools rm Remove the given Database Tools versions - m tools installed [--json] Output installed versions of the Database Tools available - m shell stable Install or activate the latest stable MongoDB Shell release - m shell X.Y.Z Install or activate the MongoDB Shell X.Y.Z - m shell ls Output the versions of the MongoDB Shell available - m shell rm Remove the given MongoDB Shell versions - m shell installed [--json] Output installed versions of the MongoDB Shell available + m tools installed [--json] Output the installed versions of the Database Tools + m mongosh stable Install or activate the latest stable MongoDB Shell release + m mongosh X.Y.Z Install or activate the MongoDB Shell X.Y.Z + m mongosh ls Output the versions of the MongoDB Shell available + m mongosh rm Remove the given MongoDB Shell versions + m mongosh installed [--json] Output the installed versions of the MongoDB Shell Events: - change Occurs when switching MongoDB versions - install Occurs when installing a previously uninstalled MongoDB version + change Occurs when switching MongoDB server versions + install Occurs when installing a previously uninstalled MongoDB server version Options: @@ -178,7 +186,7 @@ display_help() { installed lls shard sd, mongos - mongo s, sh + shell s, sh, mongo list ls, available, avail use as, mongod which bin @@ -1554,15 +1562,24 @@ execute_shard_with_version() { execute_shell_with_version() { test -z $1 && abort "version required" - local version=$(get_latest_installed_version ${1#v}) - local bin=$VERSIONS_DIR/$version/bin/mongo + + # first see if this version of mongosh is installed. fallback to legacy. + local bin=$SHELL_DIR/${1#v}/bin/mongosh + + if ! test -f $bin; then + log "mongosh version ${1#v} not found, falling back to legacy mongo shell" + local version=$(get_latest_installed_version ${1#v}) + local bin=$VERSIONS_DIR/$version/bin/mongo + fi + + debug "Shell bin: $bin" shift # remove version if test -f $bin; then $bin $@ else - abort_not_installed $version + abort_shell_not_installed ${1#v} fi } @@ -1852,9 +1869,9 @@ handle_tools() { fi } -# Handle shell commands +# Handle mongosh commands -handle_shell() { +handle_mongosh() { if test $# -eq 0; then display_shell_versions else @@ -1883,7 +1900,7 @@ else bin|which) display_bin_path_for_version $2; exit ;; as|use|mongod) shift; execute_with_version $@; exit ;; sd|shard|mongos) shift; execute_shard_with_version $@; exit ;; - s|sh|mongo) shift; execute_shell_with_version $@; exit ;; + s|sh|shell|mongo) shift; execute_shell_with_version $@; exit ;; rm) shift; remove_versions $@; exit ;; latest) install_mongo `$0 --latest`; exit ;; stable) install_mongo `$0 --stable`; exit ;; @@ -1894,7 +1911,7 @@ else install) shift; install_mongo $@; exit ;; reinstall) shift; CONFIRM=0; remove_versions $@; install_mongo $@; exit;; tools) shift; handle_tools $@; exit;; - shell) shift; handle_shell $@; exit;; + mongosh) shift; handle_mongosh $@; exit;; *) install_mongo $@; exit ;; esac shift From df99249b9253001cf235080d60dc8b9c618593c9 Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 17:09:50 -0700 Subject: [PATCH 11/13] test: added to support recent updates thanks copilot closes #160 --- test/suite.mjs | 148 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/test/suite.mjs b/test/suite.mjs index c026181..f9bb7ab 100755 --- a/test/suite.mjs +++ b/test/suite.mjs @@ -102,6 +102,7 @@ describe('m - MongoDB Version Management', { concurrency: 5 }, () => { assert.match(result.stdout, /Usage: m \[options\] \[COMMAND\] \[config\]/); assert.match(result.stdout, /Commands:/); assert.match(result.stdout, /Options:/); + assert.match(result.stdout, /Aliases:/); }); test('should display help with --help flag', async () => { @@ -213,7 +214,20 @@ describe('m - MongoDB Version Management', { concurrency: 5 }, () => { assert.match(result.stdout, new RegExp(`Activating: MongoDB Server ${version}`, 'i')); }); - test('should uninstall the version ', async () => { + test('installed version should be marked with checkmark in ls output', async () => { + const result = await run(['ls']); + assert.equal(result.exitCode, 0); + // The active version should have a checkmark + assert.match(result.stdout, new RegExp(`✔ ${version}`)); + }); + + test('installed version should be marked with checkmark in installed output', async () => { + const result = await run(['installed']); + assert.equal(result.exitCode, 0); + assert.match(result.stdout, new RegExp(`✔ ${version}`)); + }); + + test('should uninstall the version', async () => { const result = await run(['rm', version]); assert.equal(result.exitCode, 0); assert.match(result.stdout, new RegExp(`Removed MongoDB version ${version}`, 'i')); @@ -286,6 +300,105 @@ describe('m - MongoDB Version Management', { concurrency: 5 }, () => { assert.equal(result.exitCode, 0); assert.doesNotThrow(() => JSON.parse(result.stdout)); }); + + test('should show installed tools when called without arguments', async () => { + const result = await run(['tools']); + assert.equal(result.exitCode, 0); + assert.match(result.stdout, /(No installed versions|^\s*$)/); + }); + + test('should remove database tools version', async () => { + const result = await run(['tools', 'rm', '100.9.4']); + assert.equal(result.exitCode, 0); + // Should succeed or indicate version not installed + assert.doesNotMatch(result.stdout, /line \d+:/); + }); + }); + + describe('MongoDB Shell (mongosh) Commands', { concurrency: 1 }, () => { + test('should list mongosh versions with ls command', async () => { + const result = await run(['mongosh', 'ls']); + assert.equal(result.exitCode, 0); + // Should contain version numbers + assert.match(result.stdout, /\d+\.\d+\.\d+/); + }); + + // intentionally not testing ls aliases to avoid github rate limits + + test('should show installed mongosh versions (initially empty)', async () => { + const result = await run(['mongosh', 'installed']); + assert.equal(result.exitCode, 0); + assert.match(result.stdout, /(No installed versions|^\s*$)/); + }); + + test('should show installed mongosh versions with lls alias', async () => { + const result = await run(['mongosh', 'lls']); + assert.equal(result.exitCode, 0); + assert.match(result.stdout, /(No installed versions|^\s*$)/); + }); + + test('should show installed mongosh versions in JSON format', async () => { + const result = await run(['mongosh', 'installed', '--json']); + assert.equal(result.exitCode, 0); + assert.doesNotThrow(() => JSON.parse(result.stdout)); + const parsed = JSON.parse(result.stdout); + assert.ok(Array.isArray(parsed)); + }); + + test('should show installed mongosh when called without arguments', async () => { + const result = await run(['mongosh']); + assert.equal(result.exitCode, 0); + assert.match(result.stdout, /(No installed versions|^\s*$)/); + }); + + test('should remove mongosh version', async () => { + const result = await run(['mongosh', 'rm', '2.3.7']); + assert.equal(result.exitCode, 0); + // Should succeed or indicate version not installed + assert.doesNotMatch(result.stdout, /line \d+:/); + }); + + test('should handle removing multiple mongosh versions', async () => { + const result = await run(['mongosh', 'rm', '2.3.0', '2.3.1']); + assert.equal(result.exitCode, 0, `${result.stdout} ${result.stderr}`); + assert.doesNotMatch(result.stdout, /line \d+:/); + }); + + test('should install latest stable mongosh with stable command', async () => { + const result = await run(['mongosh', 'stable'], { timeout: 120_000 }); + assert.equal(result.exitCode, 0, `${result.stdout} ${result.stderr}`); + assert.match(result.stdout, /Installation complete: MongoDB Shell \d+\.\d+\.\d+/); + }); + + test('installed mongosh should appear in installed list', async () => { + await run(['mongosh', '2.5.6'], { timeout: 120_000 }); + const result = await run(['mongosh', 'installed']); + assert.equal(result.exitCode, 0, `${result.stdout} ${result.stderr}`); + assert.match(result.stdout, /2\.5\.6/); + }); + + test('should reactivate already installed mongosh version', async () => { + const installedResult = await run(['mongosh', 'installed', '--json']); + const installed = JSON.parse(installedResult.stdout); + assert.ok(installed.length > 0, 'Should have at least one installed mongosh version'); + const version = installed[0].name; // JSON uses 'name' field + const result = await run(['mongosh', version]); + assert.equal(result.exitCode, 0); + assert.match(result.stdout, /already active|Installation complete/i); + }); + + test('should clean up installed mongosh after tests', async () => { + const installedResult = await run(['mongosh', 'installed', '--json']); + const installed = JSON.parse(installedResult.stdout); + if (installed.length > 0) { + const versions = installed.map(v => v.name); // JSON uses 'name' field + const result = await run(['mongosh', 'rm', ...versions]); + assert.equal(result.exitCode, 0); + } + const installedResult2 = await run(['mongosh', 'installed', '--json']); + const installed2 = JSON.parse(installedResult2.stdout); + assert.ok(installed2.length === 0, 'Should have no installed mongosh versions'); + }); }); describe('Hook Management Commands', () => { @@ -358,6 +471,27 @@ describe('m - MongoDB Version Management', { concurrency: 5 }, () => { assert.match(result.stdout, /not installed/); }); + test('should fail to execute mongo shell with s alias for non-installed version', async () => { + const result = await run(['s', '7.0.0', '--version']); + assert.notEqual(result.exitCode, 0); + assert.match(result.stdout, /not installed/); + }); + + test('should fail to execute mongo shell with mongo alias for non-installed version', async () => { + const result = await run(['mongo', '7.0.0', '--version']); + assert.notEqual(result.exitCode, 0); + assert.match(result.stdout, /not installed/); + }); + + test('shell command should fallback to legacy mongo', async () => { + const result1 = await run(['4.4.29']); + assert.equal(result1.exitCode, 0); + + const result2 = await run(['s', '4.4.29', '--version']); + assert.equal(result2.exitCode, 0); + assert.match(result2.stdout, /version v4.4.29/); + }); + test('should succeed when removing non-installed version', async () => { const result = await run(['rm', '7.0.0']); assert.equal(result.exitCode, 0); @@ -382,6 +516,18 @@ describe('m - MongoDB Version Management', { concurrency: 5 }, () => { assert.match(result.stdout, /version required/); }); + test('should fail when no version provided to s alias', async () => { + const result = await run(['s']); + assert.notEqual(result.exitCode, 0); + assert.match(result.stdout, /version required/); + }); + + test('should fail when no version provided to mongo alias', async () => { + const result = await run(['mongo']); + assert.notEqual(result.exitCode, 0); + assert.match(result.stdout, /version required/); + }); + test('should fail when no version provided to rm command', async () => { const result = await run(['rm']); assert.equal(result.exitCode, 1); From ef4abbdffee6260bbd83c16bf1d886e8f8891ae8 Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Wed, 29 Oct 2025 17:51:59 -0700 Subject: [PATCH 12/13] fix(mongosh): x86_64 installation --- bin/m | 6 ++++++ test/suite.mjs | 32 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bin/m b/bin/m index 399d656..9ace4eb 100755 --- a/bin/m +++ b/bin/m @@ -801,6 +801,12 @@ install_shell_bin() { ext="zip" fi + if [[ $arch = "x86_64" ]]; then + # For mongosh, use x64 naming, following this doc: + # https://s3.amazonaws.com/info-mongodb-com/com-download-center/mongosh.multiversion.json + arch="x64" + fi + link="https://downloads.mongodb.com/compass/mongosh-$version-$dist-$arch.$ext" log "downloading $link" diff --git a/test/suite.mjs b/test/suite.mjs index f9bb7ab..fe0ae88 100755 --- a/test/suite.mjs +++ b/test/suite.mjs @@ -455,82 +455,84 @@ describe('m - MongoDB Version Management', { concurrency: 5 }, () => { describe('Version Management Commands (Error Cases)', () => { test('should fail to execute mongod for non-installed version', async () => { const result = await run(['use', '7.0.0', '--version']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /not installed/); }); test('should fail to execute mongos for non-installed version', async () => { const result = await run(['shard', '7.0.0', '--version']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /not installed/); }); test('should fail to execute mongo shell for non-installed version', async () => { const result = await run(['shell', '7.0.0', '--version']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /not installed/); }); test('should fail to execute mongo shell with s alias for non-installed version', async () => { const result = await run(['s', '7.0.0', '--version']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /not installed/); }); test('should fail to execute mongo shell with mongo alias for non-installed version', async () => { const result = await run(['mongo', '7.0.0', '--version']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /not installed/); }); test('shell command should fallback to legacy mongo', async () => { const result1 = await run(['4.4.29']); - assert.equal(result1.exitCode, 0); + assert.equal(result1.exitCode, 0, `${result1.stdout} ${result1.stderr}`); const result2 = await run(['s', '4.4.29', '--version']); - assert.equal(result2.exitCode, 0); - assert.match(result2.stdout, /version v4.4.29/); + if (result2.exitCode === 0) { + // Legacy mongo shell may not be installable in all CI environments + assert.match(result2.stdout, /version v4.4.29/); + } }); test('should succeed when removing non-installed version', async () => { const result = await run(['rm', '7.0.0']); - assert.equal(result.exitCode, 0); + assert.equal(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /not installed/); }); test('should fail when no version provided to use command', async () => { const result = await run(['use']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /version required/); }); test('should fail when no version provided to shard command', async () => { const result = await run(['shard']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /version required/); }); test('should fail when no version provided to shell command', async () => { const result = await run(['shell']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /version required/); }); test('should fail when no version provided to s alias', async () => { const result = await run(['s']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /version required/); }); test('should fail when no version provided to mongo alias', async () => { const result = await run(['mongo']); - assert.notEqual(result.exitCode, 0); + assert.notEqual(result.exitCode, 0, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /version required/); }); test('should fail when no version provided to rm command', async () => { const result = await run(['rm']); - assert.equal(result.exitCode, 1); + assert.equal(result.exitCode, 1, `${result.stdout} ${result.stderr}`); assert.match(result.stdout, /version.*required/); }); }); From aa0780d1b2655daea35462a3a0f1a540faca2778 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 01:07:00 +0000 Subject: [PATCH 13/13] docs: update README to reflect actual mongosh command implementation Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com> --- README.md | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f03c026..b1baaa6 100644 --- a/README.md +++ b/README.md @@ -154,28 +154,34 @@ The MongoDB Shell (mongosh) is released separately from the server. You can use List available MongoDB Shell versions: ```bash -$ m shell ls +$ m mongosh ls ``` List installed MongoDB Shell versions: ```bash -$ m shell installed +$ m mongosh installed ``` Use or download the latest stable release of the MongoDB Shell: ```bash -$ m shell stable +$ m mongosh stable ``` Use or download a specific version of the MongoDB Shell: ```bash -$ m shell 2.3.7 +$ m mongosh 2.3.7 ``` -**Note:** To execute the legacy `mongo` shell from a specific MongoDB server version, use `m s [args...]` or `m mongo [args...]` instead. +Remove previously installed MongoDB Shell versions: + +```bash +$ m mongosh rm 2.3.0 2.3.5 +``` + +**Note:** The `m shell [args...]` command will first try to use the installed mongosh version, and fall back to the legacy `mongo` shell if mongosh is not installed. ### Removing Binaries @@ -268,7 +274,7 @@ Output from `m --help`: m --legacy Install generic Linux version (does not include SSL) m use [args ...] Execute mongod with [args ...] m shard [args ...] Execute mongos with [args ...] - m s [args ...] Open a mongo shell with [args ...] + m shell [args ...] Open a mongo shell with [args ...] m bin Output bin path for m rm Remove the given version(s) m --stable Output the latest stable MongoDB version available @@ -288,16 +294,18 @@ Output from `m --help`: m tools stable Install or activate the latest stable Database Tools release m tools X.Y.Z Install or activate the Database Tools X.Y.Z m tools ls Output the versions of the Database Tools available - m tools installed [--json] Output installed versions of the Database Tools available - m shell stable Install or activate the latest stable MongoDB Shell release - m shell X.Y.Z Install or activate the MongoDB Shell X.Y.Z - m shell ls Output the versions of the MongoDB Shell available - m shell installed [--json] Output installed versions of the MongoDB Shell available + m tools rm Remove the given Database Tools versions + m tools installed [--json] Output the installed versions of the Database Tools + m mongosh stable Install or activate the latest stable MongoDB Shell release + m mongosh X.Y.Z Install or activate the MongoDB Shell X.Y.Z + m mongosh ls Output the versions of the MongoDB Shell available + m mongosh rm Remove the given MongoDB Shell versions + m mongosh installed [--json] Output the installed versions of the MongoDB Shell Events: - change Occurs when switching MongoDB versions - install Occurs when installing a previously uninstalled MongoDB version + change Occurs when switching MongoDB server versions + install Occurs when installing a previously uninstalled MongoDB server version Options: @@ -308,7 +316,7 @@ Output from `m --help`: installed lls shard sd, mongos - mongo s, sh + shell s, sh, mongo list ls, available, avail use as, mongod which bin