i know this is not important at all but might help someone.
This repository contains a PowerShell script that allows you to easily manage the MongoDB service on Windows. The script provides commands to start, stop, restart, and check the status of MongoDB. Additionally, it displays MongoDB service details such as uptime, CPU usage, and memory usage. You can also enhance the user experience by using Nerd Fonts for custom icons.
Before using the script, ensure that you have the following:
- PowerShell 7+ (or the latest version of PowerShell for Windows).
- Administrator privileges for controlling services on the system.
- Nerd Fonts (optional, for visual enhancements such as custom icons for service status).
- Start MongoDB: Start the MongoDB service.
- Stop MongoDB: Stop the MongoDB service.
- Restart MongoDB: Restart the MongoDB service.
- Status: Check the current status of MongoDB, including detailed process information like uptime, CPU usage, and memory usage.
There are several ways to download and implement this PowerShell script. Choose the method that suits you best:
- Go to the GitHub repository.
- Click the green Code button.
- Select Download ZIP.
- Unzip the file to a directory of your choice.
If you are familiar with Git, you can clone the repository directly to your local machine:
git clone https://github.com/yourusername/mongodb-service-manager.git
Once you have downloaded or cloned the repository, you can use the PowerShell script to manage your MongoDB service. The script includes the following commands:
To start the MongoDB service, use the following command:
mongodb start
To stop the MongoDB service, use the following command:
mongodb stop
To restart the MongoDB service, use the following command:
mongodb restart
To check the current status of MongoDB, including uptime, CPU usage, and memory usage, use the following command:
mongodb status
Example Output:
MongoDB Service Status: Running
MongoDB Process Details:
- Uptime: 01/09/2025 02:33:26
- CPU Usage: 0%
- Memory Usage: 344.54 MB
Once you have downloaded the script, follow these steps to implement it for use in PowerShell.
- Navigate to the folder where you downloaded or cloned the script.
- Open PowerShell in that directory and run the script by sourcing it:
.\mongodb-service.ps1
To have access to the MongoDB management functions directly from any PowerShell session, you can add the script to your PowerShell $PROFILE
.
- Edit your PowerShell
$PROFILE
file by running:
notepad $PROFILE
- Add the following line to the
$PROFILE
file to load the script automatically on startup:
. "C:\path\to\mongodb-service.ps1"
Replace
C:\path\to\mongodb-service.ps1
with the actual path where your script is saved.
- Save and close the
$PROFILE
file.
Now, when you open a new PowerShell session, the MongoDB management functions will be available for immediate use!
If you're also working with Linux, I've created a simple alias function to manage MongoDB services.
Below are some useful aliases for managing MongoDB on Linux:
mongodb() {
if [ "$1" = "start" ]; then
sudo systemctl start mongod
elif [ "$1" = "stop" ]; then
sudo systemctl stop mongod
elif [ "$1" = "restart" ]; then
sudo systemctl restart mongod
elif [ "$1" = "status" ]; then
sudo systemctl status mongod
else
echo "Usage: mongodb {start|stop}"
fi
}
You can add this function to your ~/.bashrc
or ~/.zshrc
file to use them directly from the terminal.(remmember to source ~/.zshrc or ~/.bashrc)
If you encounter any issues, here are a few common solutions:
Ensure MongoDB is installed and the service is correctly registered. You can check if the MongoDB service exists with:
Get-Service -Name MongoDB
Some commands may require administrative privileges. Ensure that you run PowerShell as Administrator.
Ensure that you have Nerd Fonts installed and the correct terminal profile (e.g., Windows Terminal, PowerShell) configured to display those icons.
This project is licensed under the MIT License.