无法通过节点休息应用程序上的mongoose连接到mongodb-altas,连接失败:“UnhandledPromiseRejectionWarning:错误:连接EACCES”

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

我在mongodb-altas上创建了一个新的集群,选择了Aws-mumbai区域,创建了一个用户,允许从任何地方访问,复制“node 3或更高版本”的连接字符串。当试图从我的节点表达休息应用程序建立连接,获得以下异常。

const mongoose=require('mongoose');
mongoose
.connect(
"mongodb+srv://anky7493:<MYPASSWORDISHERE>@dreamjob- 
i84sb.mongodb.net/test?retryWrites=true"
)
.then(() => {
console.log("Connected to database!");
})
.catch((error) => {
console.log("Connection failed!");
console.log(error);
});

在运行应用程序> nodemon索引时,下面是错误

[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index index.js`
(node:9504) DeprecationWarning: current URL string parser is deprecated,         
and will be removed in a future version. To use the new parser, pass     
option { useNewUrlParser: true } to MongoClient.connect.
now listening for request !
Connection failed!
{ Error: connect EACCES 13.127.231.212:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
errno: 'EACCES',
code: 'EACCES',
syscall: 'connect',
address: '13.127.231.212',
port: 27017 }

谁能告诉我如何与mongo-altas建立联系。提前致谢。

javascript mongoose mongodb-atlas
1个回答
0
投票

您是否尝试过使用{useNewUrlParser:true}选项?


const mongoose=require('mongoose');
mongoose
.connect(
"mongodb+srv://anky7493:<MYPASSWORDISHERE>@dreamjob- 
i84sb.mongodb.net/test?retryWrites=true"
, { useNewUrlParser: true })
.then(() => {
console.log("Connected to database!");
})
.catch((error) => {
console.log("Connection failed!");
console.log(error);
});
© www.soinside.com 2019 - 2024. All rights reserved.