A simple command-line tool to manage and connect to multiple MongoDB instances easily. This tool helps you organize and quickly access different MongoDB connections across various environments (development, production, etc.).
Built on top of mongosh.
- Save connection strings in environment namespaces (dev, beta, gamma, prod, personal, other) that mongosh cannot do natively.
- Quick connection using saved configurations
- Create, update, and delete connection configurations
- Also works with the mongosh command directly (e.g.
mgsh connect dev/myappis the same asmongosh mongodb://xxxxx1)
- Install mgsh:
curl -o- https://raw.githubusercontent.com/Warathep187/mgsh/main/scripts/install.sh | bash- Verify the installation:
mgsh # should show the help menu- If mgsh is not found, reload your shell config file (e.g.
~/.zshrcor~/.bashrc):
source ~/.zshrc # or ~/.bashrc# Show help
mgsh
# List all available connections
mgsh list
# List connections in a specific namespace (possible namespaces: dev, beta, gamma, prod, personal, other)
mgsh list dev
# Connect to the default MongoDB connection (mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000)
mgsh connect
# Connect to MongoDB using a saved connection
mgsh connect dev/myapp
# Get and copy a connection string to clipboard
mgsh get dev/myapp
# Create a new connection
mgsh create dev/myapp mongodb://xxxxx1
# Update an existing connection
mgsh update dev/myapp mongodb://xxxxx2
# Delete a connection
mgsh delete dev/myappConnections must follow the format: <namespace>/<connection-name>
Possible namespaces:
- dev
- beta
- gamma
- prod
- personal
- other
Examples: dev/myapp, prod/database1, personal/my-local-db
The project structure consists of the following files:
main.sh: Main script filerun_tests.sh: For running teststests/: Contains test filesscripts/install.sh: Installation scriptscripts/uninstall.sh: Uninstallation script
To run in development mode:
-
Clone the repository
-
Run the script directly:
./main.sh [command] [options]- Run the tests:
./run_tests.shSaved connection strings are stored in the ~/.mgsh/connections/ directory, organized by namespace.
);
curl -o- https://raw.githubusercontent.com/Warathep187/mgsh/main/scripts/uninstall.sh | bash