MongoDB:无法连接到新的副本集主服务器

问题描述 投票:1回答:1

[尝试为我的Node.JS应用程序设置MongoDB。我运行此命令:

mongo "mongodb+srv://cluster0-gjc2u.mongodb.net/test"  --username <myusername>

并且每次都得到此响应。

MongoDB shell version v4.2.1
Enter password:
connecting to: mongodb://cluster0-shard-00-00-gjc2u.mongodb.net:27017,cluster0-shard-00-01-gjc2u.mongodb.net:27017,cluster0-shard-00-02-gjc2u.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-12-07T12:14:39.630-0600 I  NETWORK  [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb.net:27017,cluster0-shard-00-01-gjc2u.mongodb.net:27017,cluster0-shard-00-02-gjc2u.mongodb.net:27017
2019-12-07T12:14:39.630-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-gjc2u.mongodb.net:27017
2019-12-07T12:14:39.631-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-gjc2u.mongodb.net:27017
2019-12-07T12:14:39.631-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-gjc2u.mongodb.net:27017
2019-12-07T12:14:40.259-0600 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for Cluster0-shard-0 is Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb.net:27017,cluster0-shard-00-01-gjc2u.mongodb.net:27017,cluster0-shard-00-02-gjc2u.mongodb.net:27017
2019-12-07T12:14:40.799-0600 I  NETWORK  [js] Marking host cluster0-shard-00-00-gjc2u.mongodb.net:27017 as failed :: caused by :: Location40659: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb.net:27017], err: AuthenticationFailed: bad auth Authentication failed.


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


2019-12-07T12:14:40.800-0600 E  QUERY    [js] Error: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb.net:27017], err: AuthenticationFailed: bad auth Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2019-12-07T12:14:40.803-0600 F  -        [main] exception: connect failed
2019-12-07T12:14:40.804-0600 E  -        [main] exiting with code 1

我已将我的IP地址列入白名单,并确保一切正常。是什么导致此问题,我该如何解决?为什么会出现此问题?

javascript node.js mongodb replicaset
1个回答
0
投票

所以您必须照顾两件事。

1)首先,在$ PATH中包含mongodb,如果还没有主目录,请在主文件夹下创建一个.bash_profile,然后插入以下内容。

export PATH =“ $ PATH:/usr/bin/mongo”确保将mongo的位置放在计算机上。如果您不知道位置,请在终端上键入whereis mongo。保存后,在终端中键入source ~/.bashrc

2)最后,从mongodb地图集复制连接链接,并在要求输入usernamepassword]时进行复制>

请提供设置来访问数据库而不是mongdb地图集帐户的凭据。

© www.soinside.com 2019 - 2024. All rights reserved.