Posted by
The Code Post
on
- Get link
- X
- Other Apps
Change MongoDB Compass Port
Method 1: Changing Port Using Command Line
- Set Environment Variables
- Click on "Edit the system environment variables" from the Start menu.
- Click on "Environment Variables".
- Click "New" to add a new system variable.
- Set Variable name to
MONGO_PORTand Variable value to your desired port number, e.g.,27018. - Click "OK" and close the window.
- Change Port Using MongoDB Command
- Type "cmd" in the Start menu and open Command Prompt.
- Enter the following command to start MongoDB on the new port:
mongod --port %MONGO_PORT%
- Test in MongoDB Compass
- Open MongoDB Compass and try connecting with the new port number. If you encounter errors or cannot connect, proceed to the second method.
Method 2: Changing Port Using Config File
- Edit Config File
- Locate the
mongod.cfgfile in the directory where MongoDB is installed and open it with a text editor. - Find the
netsection in the file and adjust the port number as follows: net: port: 27018
- Locate the
- Restart Your Computer
- Save the changes and close the config file.
- To restart the MongoDB service, either restart your computer or use the following commands in Command Prompt:
net stop MongoDB
net start MongoDB
- Test in MongoDB Compass
- Open MongoDB Compass and try connecting with the new port number. You should now be able to establish a connection.

Comments
Post a Comment