Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 24, 2025

Overview

This PR adds the ability to install and manage MongoDB Shell (mongosh) versions directly through the m tool, addressing issue #160. Users can now install mongosh just like they install MongoDB server and Database Tools.

Motivation

MongoDB Shell (mongosh) is released separately from the MongoDB server starting with MongoDB 6.0+. Previously, users had to manually install mongosh via package managers (e.g., brew on macOS) or download it manually. This PR brings mongosh management into the m tool, providing a consistent interface for managing all MongoDB components.

New Features

MongoDB Shell Installation Commands

# List all available mongosh versions
$ m mongosh ls

# Show installed mongosh versions
$ m mongosh
$ m mongosh installed

# Install the latest stable mongosh version
$ m mongosh stable

# Install a specific mongosh version
$ m mongosh 2.3.7

# Remove mongosh versions
$ m mongosh rm 2.3.0 2.3.5

Enhanced Shell Execution

The m shell <version> [args...] command now intelligently handles both mongosh and legacy mongo shells:

  • First tries to use the installed mongosh version
  • Falls back to the legacy mongo shell from the MongoDB server installation if mongosh is not installed
  • Provides helpful error messages suggesting how to install mongosh

Database Tools Enhancement

Added rm support for Database Tools:

# Remove Database Tools versions
$ m tools rm 100.9.0 100.9.1

Implementation Details

The implementation follows the same patterns established for Database Tools management:

Core Functions:

  • SHELL_DIR configuration variable for version storage ($M_PREFIX/m/shell/versions/)
  • get_all_shell_versions() fetches available versions from mongodb-js/mongosh GitHub releases
  • install_shell_bin() downloads and installs mongosh binaries from downloads.mongodb.com/compass
  • install_shell() activates a specific mongosh version
  • check_current_shell_version() detects the currently active version
  • list_shell_versions() and display_shell_versions() provide version listings
  • remove_shell_versions() removes installed mongosh versions
  • handle_mongosh() dispatches mongosh subcommands

Platform Support:

  • Linux (x86_64)
  • macOS (x86_64 and arm64)
  • Downloads .tgz for Linux, .zip for macOS (version dependent)

UX Improvements:

  • When called without arguments, m mongosh shows installed versions (consistent with m and m tools)
  • Consistent command structure across m, m tools, and m mongosh
  • Clear error messages and installation hints

Backward Compatibility

The implementation maintains full backward compatibility:

  • m shell <version> [args...] continues to work, now with intelligent mongosh/mongo fallback
  • All existing aliases (s, sh, mongo) continue to work
  • No breaking changes to existing workflows

Testing

Added comprehensive test coverage in test/suite.mjs:

  • ✅ List available mongosh versions
  • ✅ Show installed mongosh versions (plain and JSON output)
  • ✅ Install specific mongosh versions
  • ✅ Install latest stable mongosh
  • ✅ Remove mongosh versions
  • ✅ Reactivate already installed versions
  • ✅ Shell execution with mongosh/mongo fallback

Documentation

Updated both inline help (m --help) and README.md with:

  • Complete list of new mongosh commands
  • Usage examples for all features
  • Explanation of intelligent shell execution behavior
  • Clear distinction between mongosh management and shell execution

Example Usage

# Install the latest stable mongosh
$ m mongosh stable
... installing binary
Downloading from https://downloads.mongodb.com/compass/mongosh-2.3.7-linux-x86_64.tgz
... Installation complete

Activating: MongoDB Server 8.0.6, MongoDB Shell 2.3.7

# List installed versions
$ m mongosh
  * 2.3.7

# Execute mongosh directly
$ m shell 2.3.7
Current Mongosh Log ID: 67416a8c9f3e8d5c4b2a1e9f
Connecting to: mongodb://127.0.0.1:27017/
...

# If mongosh not installed, falls back to legacy mongo shell
$ m shell 7.0.0
... mongosh version 7.0.0 not found, falling back to legacy mongo shell
MongoDB shell version v7.0.0
connecting to: mongodb://127.0.0.1:27017/
...

Fixes #160

Original prompt

This section details on the original issue you should resolve

<issue_title>can you add installing shell to the tool</issue_title>
<issue_description>I believe the tool would greatly benefit from having the ability to install a shell directly. </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add installing shell capability to the tool Add MongoDB Shell (mongosh) installation support Oct 24, 2025
Copilot AI requested a review from aheckmann October 24, 2025 20:28
Copilot AI and others added 10 commits October 29, 2025 12:40
Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com>
…alidation

Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com>
Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com>
Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com>
@aheckmann aheckmann force-pushed the copilot/add-installing-shell-to-tool branch from 7e02434 to b9c9651 Compare October 30, 2025 00:11
@aheckmann aheckmann force-pushed the copilot/add-installing-shell-to-tool branch 2 times, most recently from 9adb4e0 to 0468c7d Compare October 30, 2025 00:55
@aheckmann aheckmann force-pushed the copilot/add-installing-shell-to-tool branch from 0468c7d to ef4abbd Compare October 30, 2025 01:00
@aheckmann
Copy link
Owner

@copilot Review and update this PR description to accurately reflect the changes.

Co-authored-by: aheckmann <166834+aheckmann@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot Review and update this PR description to accurately reflect the changes.

Updated the PR description to accurately reflect the implementation. Key changes:

  1. Command: Uses m mongosh (not m shell) for mongosh management
  2. New feature: m mongosh rm to remove installed versions
  3. Enhanced: m tools rm support added
  4. Smart fallback: m shell <version> tries mongosh first, falls back to legacy mongo
  5. Consistent UX: m mongosh without args shows installed versions

All documentation (README and help text) now matches the actual implementation. Commit: aa0780d

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/mongodb-js/mongosh/git/refs/tags
    • Triggering command: curl -sSf -H Accept: application/vnd.github.v3&#43;json REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@aheckmann aheckmann marked this pull request as ready for review October 30, 2025 01:12
@aheckmann aheckmann merged commit e0d86ef into master Oct 30, 2025
2 of 4 checks passed
@aheckmann aheckmann deleted the copilot/add-installing-shell-to-tool branch October 30, 2025 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

can you add installing shell to the tool

2 participants