If I have a mongo instance running, how can I check what port numbers it is listening on from the shell? I thought that db.serverStatus() would do it but I don’t see it. I see this
"connections" : {
"current" : 3,
"available" : 816
Which is close… but no. Suggestions? I’ve read the docs and can’t seem to find any command that will do this.
From the system shell you can use
lsof(see Derick’s answer below) ornetstat -anto view what a process is actually doing. However, assuming you only have access to themongoshell (which your question title implies), then you can run theserverCmdLineOpts()command. That output will give you all the arguments passed on the command line (argv) and the ones from the config file (parsed) and you can infer the portsmongodis listening based on that information. Here’s an example:If you have not passed specific port options like the ones above, then the
mongodwill be listening on 27017 and 28017 (http console) by default. Note: there are a couple of other arguments that can alter ports without being explicit, see here:https://docs.mongodb.org/manual/reference/configuration-options/#sharding.clusterRole