2
votes

I am trying to connect to mongo like this from the same host, ie. host_addr

mongo  host_addr:27030 -u user -p password

And I get the below response :

MongoDB shell version v3.4.6

connecting to: host_addr:27030

MongoDB server version: 3.4.6

2017-11-18T17:44:39.055-0800 E QUERY [thread1] Error: Authentication failed. :

DB.prototype._authOrThrow@src/mongo/shell/db.js:1461:20

@(auth):6:1

@(auth):1:2

exception: login failed

I use the same credentials to connect using Pymongo from my python application and it works.

What could be the reason?

3

3 Answers

1
votes

You need to specify which database you're authenticating against:

mongo  host_addr:27030 -u user -p password --authenticationDatabase <yourDBName>

or

mongo  host_addr:27030/<yourDBname> -u user -p password 

or

mongo --host host_addr --port 27030 -u user -p password --authenticationDatabase <yourDBName>
0
votes

I think that mongo tries to connect to the test database by default and ur user is probably on the admin db.

try:

mongo admin host_addr:27030 -u user -p password
0
votes

Adding --authenticationDatabase admin worked for me. It depends on where the login users are defined. Mine exist in System\admin database.