A simple command-line tool for managing MongoDB connection profiles.
- Profile-based connection management: Store MongoDB connection strings as named profiles
- OS keychain integration: Secure password storage
- Quick shell and query execution: Fast access to your MongoDB instances
Make sure mongosh is in your PATH.
brew tap moltinginstar/mongoctl
brew install mongoctlgit clone https://github.com/moltinginstar/mongoctl.git
cd mongoctl
go build -o mongoctl-
Create a profile:
mongoctl profile create local "mongodb://localhost:27017"
For authenticated connections, see the section on secure password input.
-
Open a MongoDB shell:
mongoctl shell local -
Or execute a query directly:
mongoctl exec local "db.users.find()"
# Create a new profile
mongoctl profile create <name> <uri>
# List all profiles
mongoctl profile list
# Get profile details
mongoctl profile get <name>
# Get only the profile URI, including username and password
mongoctl profile get <name> --field uri --show-credentials
mongoctl profile get <name> -f uri -c
# Delete a profile
mongoctl profile delete <name># Open MongoDB shell
mongoctl shell <profile> [--db <dbname>] [--verbose] [-- <mongosh-flags>]
# Execute MongoDB query
mongoctl exec <profile> "<query>" [--db <dbname>] [--file <file.js>] [--verbose]# Create profiles for different environments
mongoctl profile create dev "mongodb://localhost:27017"
mongoctl profile create prod "mongodb+srv://user:pass@cluster.mongodb.net/"
# Shell into dev
mongoctl shell dev
# Execute query against prod
mongoctl exec prod "db.stats()"
# Execute query against specific database
mongoctl exec prod "db.users.find()" --db myapp# Verbose mode for debugging
mongoctl shell local --verbose
# Pass flags to mongosh
mongoctl shell local -- --quiet --eval "db.stats()"
# Execute from file
mongoctl exec local --file query.js
# Connect to specific database
mongoctl shell prod --db analyticsWhen creating profiles with authentication, mongoctl offers three options:
Provide URI with username only - you'll be prompted for the password:
mongoctl profile create prod "mongodb://user@host/db"
# Password for user (leave empty to skip): ****echo "$MONGO_PASSWORD" | mongoctl profile create prod "mongodb://user@host/db" --password-stdinConfigure your shell to ignore commands starting with space:
# In ~/.bashrc or ~/.zshrc
export HISTCONTROL=ignorespace # bash
setopt HIST_IGNORE_SPACE # zsh
# Then prefix command with space to avoid history
mongoctl profile create prod "mongodb://user:pass@host/db"This will hide the password from your shell history but not from process lists.
Note: Passwords are automatically extracted and stored in your OS keychain. Profiles (in ~/.mongoctl/profiles/) do not contain plaintext passwords.
This project is licensed under the MIT License.