Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A simple command-line tool to manage and connect to multiple MongoDB instances easily. ๐Ÿš€

Notifications You must be signed in to change notification settings

Warathep187/mgsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MGSH (MongoDB Shell Helper)

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.

mgsh

Features

  • 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/myapp is the same as mongosh mongodb://xxxxx1)

Installation (MacOS/Linux)

  1. Install mgsh:
curl -o- https://raw.githubusercontent.com/Warathep187/mgsh/main/scripts/install.sh | bash
  1. Verify the installation:
mgsh # should show the help menu
  1. If mgsh is not found, reload your shell config file (e.g. ~/.zshrc or ~/.bashrc):
source ~/.zshrc # or ~/.bashrc

Example Usage

# 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/myapp

Connection Format

Connections must follow the format: <namespace>/<connection-name>

Possible namespaces:

  • dev
  • beta
  • gamma
  • prod
  • personal
  • other

Examples: dev/myapp, prod/database1, personal/my-local-db

Development

The project structure consists of the following files:

  • main.sh: Main script file
  • run_tests.sh: For running tests
  • tests/: Contains test files
  • scripts/install.sh: Installation script
  • scripts/uninstall.sh: Uninstallation script

To run in development mode:

  1. Clone the repository

  2. Run the script directly:

./main.sh [command] [options]
  1. Run the tests:
./run_tests.sh

Storage

Saved connection strings are stored in the ~/.mgsh/connections/ directory, organized by namespace.

Uninstallation

);

curl -o- https://raw.githubusercontent.com/Warathep187/mgsh/main/scripts/uninstall.sh | bash

About

A simple command-line tool to manage and connect to multiple MongoDB instances easily. ๐Ÿš€

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages