Mongo Atlas:自定义数据库的连接身份验证失败

and*_*a86 9 mongoose mongodb node.js

我正在尝试Mongo Atlas Cloud.我创建一个集群,我正在尝试与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 *****
Run Code Online (Sandbox Code Playgroud)

这是文档中的连接字符串.这是错误:

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
Run Code Online (Sandbox Code Playgroud)

我只能在使用管理员数据库"/ admin?"时连接到数据库.在连接字符串中.

问题:

我需要使用控制台或mongo驱动程序连接到自定义数据库.

PD:用"***"保护我的数据

Nat*_*ath 14

您使用admin数据库进行身份验证.从那里你可以切换数据库.

使用Mongo驱动程序连接时,您的连接字符串需要添加auth源:

/any_database?authSource=admin&replicaSet=xyz
Run Code Online (Sandbox Code Playgroud)


Siv*_*vli 8

添加到Nath的答案,如果您通过mongo shell连接并使用"authSource = admin"驱动程序,请使用"--authenticationDatabase admin".

用[MongoDB shell版本:3.2.8]测试