簡體   English   中英

MongoDB:無法連接到新的副本集主

[英]MongoDB: Can't connect to new replica set master

嘗試為我的 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 地址列入白名單,並確保一切正常。 什么可能導致此問題,我該如何解決? 為什么會出現這個問題?

我嘗試的是:

  1. 創建新用戶
  2. 確保連接我的應用程序時我的 mongoURI 的用戶名和密碼與我連接 mongo shell 時的用戶名和密碼相同。
  3. 在應用程序的命令行運行連接字符串。

我意識到“稍等片刻”並不是一個非常有建設性的答案,但我遇到了同樣的問題並且沒有找到解決方案的運氣,所以把它擱置了幾個小時,然后回來發現它工作得很好。

說明您的更改已部署的文本具有誤導性。 不知道為什么需要幾個小時才能啟動,但作為參考,我在使用 M0 Sandbox 集群層時發現了這一點。

所以你必須照顧兩件事。

1)首先,在你的 $PATH 中有 mongodb,如果你還沒有,在主文件夾下創建一個 .bash_profile,然后插入以下內容。(對於 Ubuntu)

export PATH="$PATH: /usr/bin/mongo " 確保將 mongo 的位置放在計算機上。 如果您不知道位置,請在終端上輸入whereis mongo 保存后,在終端中輸入source ~/.bashrc

2)最后,從mongodb圖集中復制連接鏈接,並在要求輸入usernamepassword

請提供訪問數據庫的憑據設置,而不是 mongdb atlas 帳戶。

此解決方案可能特定於 Cloud MongoDB 提供的 mLabs 到 MongoDB Atlas 遷移工具。

我的決心是:

  1. 重新創建相同用戶名的用戶
  2. 從特定的 mLabs 授予更改為 Atlas 內置角色
  3. 設置新憑據,我還避免使用特殊字符。

祝你好運!

創建一個沒有任何特殊字符的簡單密碼,它只包含字母和數字。

我無法訪問,但更改密碼對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM