In the system shell, you can use lsof (see Derick's answer below) or netstat -an to see what the process actually does. However, assuming you have access to the mongo shell (which implies the name of the question), you can run the serverCmdLineOpts() command. This output will give you all the arguments passed on the command line (argv), and those from the configuration file (parsed), and you can conclude that the mongod ports mongod listened based on this information. Here is an example:
db.serverCmdLineOpts() { "argv" : [ "./mongod", "-replSet", "test", "--rest", "--dbpath", "/data/test/r1", "--port", "30001" ], "parsed" : { "dbpath" : "/data/test/r1", "port" : 30001, "replSet" : "test", "rest" : true }, "ok" : 1 }
If you did not pass certain port parameters, such as above, then mongod will listen on 27017 and 28017 ( http console ) by default. Note. There are several other arguments that ports can change without being explicit, see here:
https://docs.mongodb.org/manual/reference/configuration-options/#sharding.clusterRole
Adam Comerford Feb 20 2018-12-12T00: 00Z
source share