Mongo connection failed

vagrant@m103:~$ mongo
MongoDB shell version v3.6.15
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2019-11-19T13:24:05.429+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2019-11-19T13:24:05.435+0000 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13

Hello. You run mongo daemon on specific port.
So You should pass this port as option to mongo command to specify which port should be connected.

I did exactly that, but when i want to show dbs, i get the following error. how can get out of the port?

vagrant@m103:~$ mongo --port 27000
MongoDB shell version v3.6.15
connecting to: mongodb://127.0.0.1:27000/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“55be8618-bdf2-4419-a7e1-56e2a60171d1”) }
MongoDB server version: 3.6.15
MongoDB Enterprise > show dbs
2019-11-19T14:02:49.868+0000 E QUERY [thread1] Error: listDatabases failed:{
“ok” : 0,
“errmsg” : “there are no users authenticated”,
“code” : 13,
“codeName” : “Unauthorized”
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:67:1
shellHelper.show@src/mongo/shell/utils.js:860:19
shellHelper@src/mongo/shell/utils.js:750:15
@(shellhelp2):1:1

It is ‘Localhost exception’ You cannot execute this command without any admin user.
You should create admin user and to be logged in by him to be able execute this command
–UPD
If You already have created user, than you should just execute db.auth(‘login’,‘password’) .
What command for launching mongod ?

Hi @Jacob_28713,

As @Leonid_75050 mentioned, Using the Localhost exception create your first user and then authenticate using the db.auth() function.

Hope it helps!

If you have any other query then please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

I have done that but i’m still getting the follow error.

vagrant@m103:~$ mongo --port 27000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
MongoDB shell version v3.6.15
connecting to: mongodb://127.0.0.1:27000/?authSource=admin&gssapiServiceName=mongodb
2019-11-19T15:44:14.811+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27000, in(checking socket for error after poll), reason: Connection refused
2019-11-19T15:44:14.811+0000 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:27000, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

Are You shure that You have ran mongod on 27000 port? could You provide us command (and config if it used) for running mongod ?

Hi @Jacob_28713,

The error message says that it couldn’t connect to the mongod instance running on the provided host and port. Can you please make sure you have a mongod instance running on the port 27000 ?

In addition to that, please share the output of the following command.

ps -ef | grep mongod

If you have run the mongod instance using a configuration file then also share the content of the configuration file.

Thanks,
Shubham Ranjan
Curriculum Support Engineer