【问题标题】:unable to connect to mongodb-altas through mongoose on node rest app, connection failed : "UnhandledPromiseRejectionWarning: Error: connect EACCES"无法通过节点休息应用程序中的猫鼬连接到 mongodb-atlas,连接失败:“UnhandledPromiseRejectionWarning:错误:连接 EACCES”
【发布时间】:2019-09-02 18:47:17
【问题描述】:

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

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);
});

on run application > nodemon index, 下面是错误

[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】:

    您是否尝试过使用 { 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);
    });
    

    【讨论】:

    • 是的,它也尝试了选项参数和异常处理
    猜你喜欢
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 2021-10-25
    相关资源
    最近更新 更多