Mongo Atlas:连接身份validation失败,自定义数据库
我正在尝试Mongo Atlas Cloud。 我创build一个集群,我正在尝试与mongo shell的连接:(与mongo驱动程序相同的问题)
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 *****
这是文档中的连接string。 这是错误的:
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
只有当我使用pipe理数据库“/ admin?”时才可以连接到数据库 在连接string中。
问题:
我需要连接到控制台或mongo驱动程序的自定义数据库。
PD:我用“***”来保护我的数据
您使用pipe理数据库进行身份validation。 从那里你可以切换数据库。
当使用Mongo驱动程序连接时,连接string需要添加auth源代码:
/any_database?authSource=admin&replicaSet=xyz
添加到Nath的答案,使用“–authenticationDatabasepipe理”,如果你通过mongo shell连接,并使用“authSource =pipe理”的驱动程序。
用[MongoDB shell版本:3.2.8]testing
"authSource=admin"
是所有Atlas连接的要求。