How to Check Which MongoDB Version Is Currently Active Using m
The m version manager determines the active MongoDB installation by executing mongod --version from the symlinked $M_BIN_DIR directory and parsing the output to extract the version string, including Enterprise edition detection.
The m tool by aheckmann/m is a lightweight MongoDB version manager that simplifies switching between server releases. When you activate a specific MongoDB version, m creates symbolic links in a dedicated binary directory, enabling quick identification of which build is currently in use. Understanding how to check which MongoDB version is currently active using m ensures you're running the expected server in your development or production environments.
How m Detects the Active MongoDB Version
At the core of version detection is the symlinked binary directory referenced by the $M_BIN_DIR environment variable. When you activate a version, m populates this directory with symbolic links pointing to the selected release's bin folder (excluding a few tool binaries).
The check_current_version function defined in bin/m (lines 40-48) performs the actual runtime detection:
check_current_version() {
which $M_BIN_DIR/mongod &> /dev/null
if test $? -eq 0; then
active=`$M_BIN_DIR/mongod --version | grep "version\s*v[0-9]" \
| grep -E -o '[0-9]+\.[0-9]+\.[0-9]+([-_\.][a-zA-Z0-9]+)?' | head -1
ent=`$M_BIN_DIR/mongod --version | grep -E '(modules\"?:|\"?enterprise\"?)' \
| grep -v -E 'modules"?:[[:space:]]*\[.*' | grep -v -E 'modules"?:[[:space:]]*none'`
if [[ $ent == *1 ]]; then active="$active-ent"; fi
fi
}
This function runs $M_BIN_DIR/mongod --version and uses grep patterns to extract the semantic version number. It also detects Enterprise builds by checking the output for enterprise modules or specific module declarations, appending -ent to the version string when applicable.
Commands to Check the Active MongoDB Version
List Installed Versions with the Active Indicator
Running m without arguments invokes display_versions, which internally calls check_current_version before printing. According to the aheckmann/m source code, the active version appears with a ✔︎ marker:
$ m
5.0.15
6.0.5
✔ 7.0.12
Display the Binary Path of the Active Version
The m bin command utilizes display_bin_path_for_version to print the absolute path to the currently active version's bin directory. This resolves the symlinks in $M_BIN_DIR to their actual installation location:
$ m bin
/home/youruser/.local/m/versions/7.0.12/bin
Query Specific Version Paths
To verify the installation path of a specific release without activating it, use m bin <version> or m which <version>. This returns the path to the latest installed version matching the provided identifier:
$ m bin 6.0.5
/home/youruser/.local/m/versions/6.0.5/bin
Practical Usage Examples
Here are common workflows for verifying your MongoDB environment using the m CLI:
# Check which version is active (marked with ✔︎)
$ m
# Get the absolute path to the active version's binaries
$ m bin
# Verify the path for a specific installed version
$ m which 5.0.15
# Start the currently active mongod directly
$ m use
Summary
- Symbolic link inspection:
midentifies the active version by examining symlinks in the$M_BIN_DIRdirectory that point to the selected release. - Version parsing: The
check_current_versionfunction inbin/mexecutesmongod --versionand extracts the version using regex pattern matching. - Enterprise detection: The tool automatically appends
-entto the version string when it detects Enterprise modules in the binary output. - User commands: Use
mto list versions with indicators,m binto show the active path, andm bin <version>to query specific installations.
Frequently Asked Questions
How does m determine which MongoDB version is active?
The tool checks the $M_BIN_DIR environment variable for existing symlinked binaries and executes mongod --version from that location. The check_current_version function parses the command output to extract the semantic version number and detect if it's an Enterprise build.
What is $M_BIN_DIR in the m version manager?
$M_BIN_DIR is the directory where m creates symbolic links to the currently activated MongoDB version's binaries. This directory typically resides at ~/.local/m/bin and contains symlinks to mongod, mongo, and other server tools that resolve to the active version's installation path.
Can m detect if I'm running MongoDB Enterprise Edition?
Yes. The check_current_version function specifically searches the mongod --version output for enterprise modules or the "enterprise" string. When detected, it appends -ent to the version identifier shown in the listing output.
How do I switch to a different MongoDB version using m?
Run m use <version> to activate a specific release. This command updates the symlinks in $M_BIN_DIR to point to the requested version's installation directory, immediately making it the new active version for all subsequent MongoDB operations.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →