You can easily change the port number with the help of the mongodb.config file. What you have to do is open your /path/mongod.conf in your code editor and then search for the following code:
net:
port: 27017
When you find that code then just change the port number as per your choice and save that file and reload the mongod with the help of the following command:
$ sudo service mongodb restart
[ ok ] Restarting database: mongod.
But while performing all of the above steps you have to keep one thing in mind that the new port number must be equal to or greater than 1000 and the new port number must not be taken by any other service running on the same host.
Learn MongoDB and excel in your web development career!
Also, have a look at this professional Full Stack Developer Training, designed to enhance your skills in the field.