Search code examples
node.jsmongodbamazon-web-servicesbitnami

Unable to connect to mongodb in shell and with mongoose. Working with Robo3T


Hello together something seems to be wrong with my commands. I can connect to my mongodb with Robo 3T. But if i make a connection string like.

let url = mongodb://root:PASSWORD@10.0.1.185:27017/tbAuth

mongoose.connect(url, { auto_reconnect: true })
        .catch((err) => {
            console.error('App starting error:', err);

The Error:

App starting error: { MongoError: Authentication failed.
    at Function.MongoError.create (/var/app/current/node_modules/mongodb-core/lib/error.js:31:11)
    at /var/app/current/node_modules/mongodb-core/lib/connection/pool.js:489:72
    at authenticateStragglers (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:435:16)
    at Connection.messageHandler (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:469:5)
    at Socket.<anonymous> (/var/app/current/node_modules/mongodb-core/lib/connection/connection.js:321:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)
  name: 'MongoError',
  message: 'Authentication failed.',
  ok: 0,
  errmsg: 'Authentication failed.',
  code: 18,
  codeName: 'AuthenticationFailed' }

or if i ssh onto the server via ssh and try to connect

mongo -u root -p PASSWORD

it fails.

The authentication mechanism ist SCRAM-SHA-1 It explicitly states that it is an Authentication error.

MongoDB shell version v3.6.3
connecting to: mongodb://%2Fopt%2Fbitnami%2Fmongodb%2Ftmp%2Fmongodb-27017.sock/
MongoDB server version: 3.6.3
2018-03-31T22:44:44.238+0000 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20
@(auth):6:1
@(auth):1:2
exception: login failed

Any Ideas what could be the issue? I already removed the auth requirement and reset the password for the user but it still fails.. If i remove the auth requirement everything works fine so the server is reachable and the db is running.

The server is on aws created with bitnami.


Solution

  • If found the answer myself.

    For anyone struggling. Be sure to use sudo and connect to admin.

    sudo mongo admin --username root --password password
    

    And for the mongoose connection string:

    mongodb://root:PASSWORD@10.0.1.185:27017/tbAuth?authSource=admin
    

    ?authSource=admin did the trick for me