当前位置: 首页 > 知识库问答 >
问题:

错误:“无法连接到MongoDB Atlas群集中的任何服务器”

俞涵涤
2023-03-14

我的节点应用程序向我发送了这样一条消息:“无法连接到MongoDB Atlas群集中的任何服务器。请确保您当前的IP地址在Atlas群集中的IP白名单上。”。

我已经添加了我当前的IP地址以及IP白名单上的0.0.0.0。

下面是错误消息的图片和我编写的连接它的代码。我是node.js和mongoDB的新手。我查看了这里的所有解决方案,但没有一个能够解决这个问题。

var express = require('express');
var bodyparser = require('body-parser');
var mongoose = require('mongoose');

var app = express();
app.use(bodyparser.json());

mongoose
     .connect("mongodb+srv://<username:password>@my-cluster.mongodb.net/test?retryWrites=true&w=majority", 
     { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
     .then(() => console.log( 'Database Connected' ))
     .catch(err => console.log( err ));

    app.listen(3003)

这是我在运行nodemon后收到的错误。

[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
MongooseError [MongooseServerSelectionError]: Could not connect to any servers in your MongoDB Atlas cluster. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/.
    at new MongooseServerSelectionError (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\node_modules\mongoose\lib\error\serverSelection.js:24:11)
    at NativeConnection.Connection.openUri (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\node_modules\mongoose\lib\connection.js:823:32)
    at Mongoose.connect (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\node_modules\mongoose\lib\index.js:333:15)
    at Object.<anonymous> (C:\Users\anna james\Dropbox\MERN_SHOPPING_LIST\back\server.js:9:7)
    at Module._compile (internal/modules/cjs/loader.js:1157:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  message: "Could not connect to any servers in your MongoDB Atlas cluster. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/.",
  name: 'MongooseServerSelectionError',
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster1-shard-00-01-m3rzz.mongodb.net:27017' => [ServerDescription],
      'cluster1-shard-00-02-m3rzz.mongodb.net:27017' => [ServerDescription],
      'cluster1-shard-00-00-m3rzz.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  },
  [Symbol(mongoErrorContextSymbol)]: {}
}


错误消息和代码

共有3个答案

翟京
2023-03-14
Follow below steps:
1] Go to https://www.mongodb.com/cloud/atlas
2] login to your mongodb atlas account
3] Click on network access

i] if you have already added ip address, then here you can see ip access list
a] click on delete 

ii] if you have not already added ip address, then just follow below steps:

4] click on add ip address
5] select 'add current ip address' or if you want you can also select 'allow access from anywhere'
6] type in comment if you want
7] click on confirm button
8] this will show pending loader, wait until it shows active status
9] now restart your server on terminal by typing 'npm start'

-- That's it!
尉迟雅昶
2023-03-14

你在使用代理吗??请先尝试不同的互联网连接。

齐献
2023-03-14

尝试这样做:-MongoDB Atlas-

这对我有用!

 类似资料:
  • 我有一个问题,我试图解决了很长一段时间。我正试图通过从连接到Mongo Atlas云。这不是我第一次,但我就是找不到答案。 猫鼬版本:5.9.22 这是我的代码: 我的白名单设置仅包括0.0.0.0/0我在数据库访问中的用户名和密码非常简单,没有任何特殊字符,但总是出现相同的错误: 谢谢。

  • 我使用node创建了一个RESTAPI,并使用Kubernetes和Docker对其进行了容器化。出于开发目的,kubernetes吊舱在minikube环境中运行。 该应用程序运行良好,现在给出了以下错误。 该问题似乎是MongoDB连接URL/Access问题,但连接字符串是正确的。(使用MongoDB Cloud支持仔细检查)。每个人都有相关的网络访问权限 我还可以确认可以使用相同的连接UR

  • 我有一个问题已经一个月了,但我没有找到解决办法。我的笔记本电脑和个人电脑都有这些问题(我以前启动过mongod): 错误:无法连接到服务器 127.0.0.1:27017 src/mongo/shell/mongo.js:91 异常:连接失败 错误:无法连接到服务器127.0.0.1:27017 src/mongo/shell/mongo。js:93异常:连接失败 错误:无法连接到服务器127.0

  • 我在我的本地专用网络中有卡桑德拉,我正在尝试从另一台PC访问,但在连接到卡桑德拉服务器时,我收到此错误。 ('无法连接到任何服务器',{'192.168.1.170':ConnectionRefusedError(10061,“尝试连接到[('192.188.1.170',9042)]。上一个错误:由于目标计算机主动拒绝,无法建立连接”)}) 有人能帮帮我吗?

  • 问题内容: 关闭。 这个问题是题外话。它当前不接受答案。 想改善这个问题吗? 更新问题,使其成为Stack Overflow 的主题。 7年前关闭。 我在linux框IP = 192.168.1.100上安装了mysql服务器,但是当我尝试连接到该IP时总是出错(111)。但是使用localhost并且127.0.0.1可以。 从另一台计算机连接它也会出现错误111。 在这种情况下,使用local

  • 我正在尝试在我的本地计算机上运行,并从 收到错误。 错误消息为:< code >无法连接到服务器:拨tcp 192.168.2.15:8443: connectex:无法建立连接,因为目标计算机主动拒绝连接。 请看下面的截图。 我已经尝试了无法在windows 10上运行Kubernetes (kubectl)和Minikube中的所有建议。无法连接到服务器:拨tcp [::1]:8080: co