Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure new port for mongodb

Tags:

mongodb

I am currently using port 27017 for mongodb and everything is working proper. We want to configure new port for security purpose.

Can you help me how we can configure this?

like image 731
Rohit Bhalani Avatar asked Dec 06 '25 06:12

Rohit Bhalani


2 Answers

This way,

  1. While startiing mongo pass port argument

    mongod --port your desired port

    mongod --port 19000

    Start Mongo with port:

    mongo --port your desired port

    mongo --port 19000

2.change the port in the mongodb.config file and pass the config file as input.

port = Ur desired port

like image 157
VeKe Avatar answered Dec 08 '25 00:12

VeKe


Change the /etc/mongod.conf file for persistence

change net: section as

net:
   bindIp: 127.0.0.1
   port: <The port number you want to listen>

Command line option --port <port> can also be used but will not remain persistent and you need to specify the same every time you start Mongod

like image 37
Deepak Kr Gupta Avatar answered Dec 08 '25 00:12

Deepak Kr Gupta