Mongo Atlas: Connection Authentication Failure with User Databases

I'm trying a cloud of Mongo Atlas. I am creating a cluster and I am trying to establish 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 a mistake:

 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 the admin database "/ admin?". in the connection string.

PROBLEM:

I need to connect to a user database using console drivers or mongo.

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

+6
source share
3 answers

You are authenticating with the admin database. From there you can switch the database.

When connecting using Mongo drivers, your connection string should add an auth source:

 /any_database?authSource=admin&replicaSet=xyz 
+9
source

When adding Nath to your answer, use "--authenticationDatabase admin" if you are connecting through the mongo shell and using "authSource = admin" for the drivers.

Tested with [MongoDB Shell Version: 3.2.8]

+6
source

"authSource=admin" This is a requirement for all Atlas connections.

+1
source

All Articles