gpt4 book ai didi

node.js - 错误 : "Could not connect to any servers in your MongoDB Atlas cluster"

转载 作者:行者123 更新时间:2023-12-03 12:10:22 26 4
gpt4 key购买 nike

我的 Node 应用程序给了我这条消息
“无法连接到您的 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)]: {}
}



Error Message and code

最佳答案

尝试这样做 :- MongoDB Atlas -> NetworkAccess -> Edit -> Allow Any这对我有用!

关于node.js - 错误 : "Could not connect to any servers in your MongoDB Atlas cluster",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61937581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com