Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo Atlas: Connection authentication failed with custom databases

I am trying the Mongo Atlas Cloud. I create a cluster and i am trying a connection with the mongo shell: (same problem with mongo drivers)

mongo mongodb://***-cluster-shard-00-00-***.mongodb.net:27017,***-cluster-shard-00-01-***.mongodb.net:27017,***-cluster-shard-00-02-***.mongodb.net:27017/any_database?replicaSet=****-Cluster-shard-0 --ssl --username ***** --password *****

this is the connection string in the documentation. And this is the error:

MongoDB shell version: 3.2.7
connecting to: mongodb://***-cluster-shard-00-00-***.mongodb.net:27017,***-cluster-shard-00-01-***.mongodb.net:27017,***-cluster-shard-00-02-***.mongodb.net:27017/any_database?replicaSet=***-Cluster-shard-0
2016-07-07T01:31:17.535-0300 I NETWORK  [thread1] Starting new replica set monitor for ***-Cluster-shard-0/***-cluster-shard-00-00-***.mongodb.net:27017,***-cluster-shard-00-01-***.mongodb.net:27017,***-cluster-shard-00-02-***.mongodb.net:27017
2016-07-07T01:31:17.535-0300 I NETWORK  [ReplicaSetMonitorWatcher] starting
2016-07-07T01:31:20.084-0300 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(auth):6:1
@(auth):1:2

exception: login failed

I can connect to the database only when i use admin database "/admin?" in the connection string.

THE PROBLEM:

I need to connect to a custom database with the console or mongo drivers.

PD: i protect my data with "***"

like image 370
andrescabana86 Avatar asked Jul 07 '16 04:07

andrescabana86


People also ask

Why is MongoDB not connecting to Atlas?

If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.

Why is my MongoDB 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 do I authenticate a database in MongoDB?

To authenticate as a user, you must provide a username, password, and the authentication database associated with that user. To authenticate using the mongo shell, either: Connect first to the MongoDB or mongos instance. Run the authenticate command or the db.


1 Answers

You authenticate with the admin database. From there you can switch the database.

When connecting using Mongo drivers, your connection string needs add the auth source:

/any_database?authSource=admin&replicaSet=xyz
like image 115
Nath Avatar answered Sep 28 '22 08:09

Nath