EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials MongoDB Tutorial MongoDB port
 

MongoDB port

Updated March 8, 2023

MongoDB port

 

 

Introduction to MongoDB port

MongoDB port is the address where the protocol tries to establish the connection. There are some default ports supported by MongoDB such as 27017. However, we can also explicitly modify the default ports. MongoDB is a request-response kind of application that involves establishing a connection between its client and server involving multiple requests and responses which is based on sockets and the protocol used is TCP/ IP (Transport Layer Protocol) socket protocol. For exchanging the information, data, requests, and responses the sockets have their associated ports. Which port needs to be considered while communicating depends upon the internal configuration settings.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

In this article, we will have a look at some of the default ports used by Mongo DB and also have a look at the process of changing the default ports.

List of default ports

Let us have a look at all the related default ports used by Mongo DB database management system. For this check out the following table –

Default Port Address Explanation
28017 While showing the status on the web pages this port address is considered by default.
27019 When we are performing a runtime operation in the system and while running the same, we are making the use of –configsvr option then this port address is considered as the default port.
27018 When we are performing a runtime operation in the system and while running the same, we are making the use of –shardsvr option then this port address is considered as the default port.
27017 For all the instances of Mongos and Mongod this port address is considered by default for establishing the communication.

Syntax:

Let us understand the syntax of the URL used for establishing the connection. Consider a sample URL for studying the various components present inside it –

mongodb://localhost:27017/educba

Let us discuss one by one all the components used in the above statement –

Mongodb:// – This is the definition of the protocol. Hence, when using the mongo db the protocol specification is given by using mongodb://

Localhost:27017c- It is the part that represents the address of the server with which we are trying to establish the connection.

Localhost – It is the address of the server

27017 – This is the port address that is considered for identification of socket by default when using MongoDB.
/educba – It is the name of the database to which we want to connect to.

Changing the default port address of MongoDB

There are plenty of ways using which we can modify the port which is being used by Mongo DB for a specific task. Before you go for modifying any of the default ports to a port of your choice, you need to make sure that there is no other application that is using the same port number you are trying to set the Mongo DB port to. Let us have a look at some of the methods to change the default port address one by one in the upcoming section –

First Method

We will have to begin the server of Mongo DB by specifying – port argument in its statement while firing the command. For this, we have to make sure that while opening the command prompt we open it with administrator privileges and role, and then we have to navigate to the bin folder present in Mongo DB installation directory. Further, you need to enter the command specified below –

mongod –dbpath “C:Datadb” –port 20000

After firing the above command, you will observe that the connection waiting message is displayed as shown below –

MongoDB port 1

Further, the next step to perform is to open a new instance of the command prompt with the role and privileges of the administrator and then navigate to the bin folder of MongoDB installation directory and type the same command that is shown below –

Mongo --port 20000

The output of the above command will be as shown below which means that the mongo DB is now running on the specified port address 20000 instead of its default port address –

MongoDB port 2

In this way, by using the above methodology and commands we can initiate the Mongo DB server at any custom port as per our requirement. Only the thing to be taken care of is that there should not be any service or application that is running on the port on which we are trying to establish the Mongo DB connection.

Second Method

In the second method, we will have to modify the configuration file of Mongo DB and modify the port address specified in the configuration details. For this, you will have to follow the below steps –

  • We will have to first create a file with YAML format which will act as the configuration file for our Mongo DB. We will give the name for this file as “mongod.conf”.
  • Next, you have to run the configuration file along with specifying the –config option value to a location of any of the configuration file to which you want it to refer. For example, if we have created mongod.conf file then we will specify the command as

mongod --config /etc/mongod.conf

The output of above command is as shown in the below image –

MongoDB port 3

Let us have a look at one of the sample configuration files. For this refer to the below image. We can observe that the file contains the port specification as 20000 which was kept as per our requirement. You can change this port value by specifying the required port number in the commands used above.

output

We can now observe the process of changing the port is successfully completed.

By using either of the two methods, you can change the default port number of Mongo DB to whichever address you want. After this, your next step will be establishing the connection with Mongo DB.

Conclusion

The default port of the Mongo DB is already predefined and set for the Mongo and Mongod instances when using configsvr or shardvsr option while runtime operations or even when observing the status in web pages which are mentioned in the table. We can even modify the port number by using either of the two methods specified in the above article.

Recommended Articles

This is a guide to MongoDB port. Here we discuss the introduction, List of default ports with some methods respectively. You may also have a look at the following articles to learn more –

  1. MongoDB Skip()
  2. MongoDB Relationships
  3. MongoDB Users
  4. MongoDB Import

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW