Is it true that by default mongos and mongod use the same port - 27017?

I had to pick a different port for one of these two, for example --port 37017 for mongos.


Yes, they have the same default port. Generally, the most common production set up is to have the mongos running on the application server, not the same host as the mongod, hence it is rare for this to cause a problem once you go beyond a development environment - if you are running a replica set on a single host for testing you similarly have to alter the ports for each mongod process.

There are a few reasons to run as you suggest (security policy, certain data distribution patterns), but as you have discovred, if you alter the port appropriately there is no issue running mongos and mongod on the same host.

  • My understanding is without sharding, mongo client/shell will connect to mongod at port 27017. With sharding, mongo client/shell will connect to mongos at port 27017. Is that correct? – johnsam Jul 8 '13 at 13:28
  • I can see it's value to seperate the two. However, if I set up all mongo stuff on the db nodes which means mongos and mongod are on the same nodes. And leave application node which only contains mongo client, I think that's more cleaner. In case my mongo i/o is not too heavy, I mix mongodb with application in the same node, that should be allowed too? I hope such flexibility is not unacceptable? – johnsam Jul 8 '13 at 13:32
  • 1
    It's not that its unacceptable or acceptable (unless you hit resource issues), you just need to change ports if you run everything on the same host. The mongo shell will connect to localhost on port 27017 by default, it does not care whether the mongod or the mongos is running on that port - it can talk to either. You need to use the --port argument for the mongo shell to talk to the appropriate process as needed – Adam C Jul 8 '13 at 15:13
  • As of version 2.6, mongod, when run with the --shardsrv option, listens to port 27019. Not sure wether this is true for v>2.6 – Markus W Mahlberg May 13 '15 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.