Mongo Atlas:自定义数据库的连接身份验证失败 [英] Mongo Atlas: Connection authentication failed with custom databases
问题描述
我正在尝试Mongo Atlas云.我创建了一个集群,并且正在尝试与mongo shell进行连接:(与mongo驱动程序相同的问题)
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
仅当我使用管理数据库"/admin?"时,我才能连接到数据库.在连接字符串中.
I can connect to the database only when i use admin database "/admin?" in the connection string.
问题:
我需要使用控制台或mongo驱动程序连接到自定义数据库.
I need to connect to a custom database with the console or mongo drivers.
PD:我使用"***"保护我的数据
PD: i protect my data with "***"
推荐答案
您需要通过管理数据库进行身份验证.从那里可以切换数据库.
You authenticate with the admin database. From there you can switch the database.
使用Mongo驱动程序进行连接时,您的连接字符串需要添加auth来源:
When connecting using Mongo drivers, your connection string needs add the auth source:
/any_database?authSource=admin&replicaSet=xyz
这篇关于Mongo Atlas:自定义数据库的连接身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!