You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with the default port of 27017: mongosh Note macOS Prevents mongosh From Opening macOS may prevent mongosh from running after installation. Under the General tab, click the button to the right of the. Start a mongosh session on the same host machine as the mongod. Here's an example: db.serverCmdLineOpts() Run MongoDB Community Edition Open System Preferences Select the Security and Privacy pane. 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 ports mongod is listening based on that information.
However, assuming you only have access to the mongo shell (which your question title implies), then you can run the serverCmdLineOpts() command.
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. educba It is the name of the database to which we want to connect to. From the system shell you can use lsof (see Derick's answer below) or netstat -an to view what a process is actually doing. 27017 This is the port address that is considered for identification of socket by default when using MongoDB.