Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix: 'MongoError: authentication fail' @MongoDB Atlas

I am connecting to MongoDB Atlas and getting authentication fail error.

that is my connection string:

mongodb://user:<password>@mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true

That is what I get:

------------------------------------------------

    Mongoose connection "error" event fired with:

    { MongoError: authentication fail
        at Function.MongoError.create (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:31:11)
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/replset.js:1245:38
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:760:7
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:736:20
        at finish (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:168:16)
        at handleEnd (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:178:7)
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:269:11
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:469:18
        at process._tickCallback (internal/process/next_tick.js:61:11)
      name: 'MongoError',
      message: 'authentication fail',
      errors:
       [ { name: 'mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017',
           err: [Error] },
         { name: 'mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017',
           err: [Error] } ] }
    Error: KeystoneJS (Keystone Demo) failed to start - Check that you are running `mongod` in a separate process.
        at NativeConnection.<anonymous> (/mnt/c/WEB/keystone-md2/node_modules/keystone/lib/core/openDatabaseConnection.js:62:10)
        at NativeConnection.emit (events.js:189:13)
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/lib/connection.js:824:17
        at connectCallback (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:527:5)
        at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:459:13
        at process._tickCallback (internal/process/next_tick.js:61:11)
like image 856
evil-cat Avatar asked Apr 27 '19 17:04

evil-cat


People also ask

What does authentication failed mean?

If you receive this error message, that means that the username and/or password that you have entered is incorrect. The error message states “Authentication failed! Try again.” You may have locked your account after too many attempts and your account will need to be reset.

Why MongoDB compass is not connecting?

Ensure Your MongoDB Instance is Running Compass must connect to a running MongoDB instance. Make sure you have installed MongoDB and have a running mongod process. You should also check that the port where your MongoDB instance is running matches the port you provide in the Compass connect dialog.

How connect MongoDB Atlas to Nestjs?

Go to your MongoDB Atlas Account, go to your cluster and click the Connect button. Copy the string replacing the “username” for the one that you created in your MongoDB Cluster, also replace the “<password>” and finally replace “test” for the name of your collection inside the Database you created before.


1 Answers

You have to put your user and password in your connection uri string

 mongodb://***'your user':' here comes password '***@mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true

e.g

 mongodb://dbuser:[email protected]:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
like image 100
Muhammad Shareyar Avatar answered Sep 28 '22 07:09

Muhammad Shareyar