AWS文档DB不从Node.js应用程序工作

发布于 2025-01-22 18:57:34 字数 1882 浏览 4 评论 0 原文

Express.js代码

    var mongoose = require("mongoose");
    const { db } = require("../../models/userModel");
    mongoose.connect("mongodb://cnoxbeta:abdf1234@cnox-beta-document-db.cluster-cvzxy5kwx8pn.us-west-2.docdb.amazonaws.com:27017/cnox?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false");

错误:

    (node:1239) UnhandledPromiseRejectionWarning: Error: error:0909006C:PEM routines:get_name:no start line
        at Object.createSecureContext (_tls_common.js:149:17)
        at Object.connect (_tls_wrap.js:1580:48)
        at makeConnection (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:274:31)
        at connect (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:33:5)
        at checkServer (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/monitor.js:201:27)
        at /home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/monitor.js:231:9
        at executeAndReschedule (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/utils.js:791:9)
        at makeInterruptibleAsyncInterval (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/utils.js:798:9)
        at Monitor.connect (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/monitor.js:87:71)
        at Server.connect (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/server.js:100:28)
    (Use `node --trace-warnings ...` to show where the warning was created)

我使用AWS文档DB连接我的节点应用程序。 我能够使用Shell访问Mongo DB,因此MongoDB很好,并且访问IP白色列表很好。连接中有问题。 请看一下如何修复此

注意:我能够使用shell连接

express.js code

    var mongoose = require("mongoose");
    const { db } = require("../../models/userModel");
    mongoose.connect("mongodb://cnoxbeta:abdf1234@cnox-beta-document-db.cluster-cvzxy5kwx8pn.us-west-2.docdb.amazonaws.com:27017/cnox?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false");

error:

    (node:1239) UnhandledPromiseRejectionWarning: Error: error:0909006C:PEM routines:get_name:no start line
        at Object.createSecureContext (_tls_common.js:149:17)
        at Object.connect (_tls_wrap.js:1580:48)
        at makeConnection (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:274:31)
        at connect (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:33:5)
        at checkServer (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/monitor.js:201:27)
        at /home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/monitor.js:231:9
        at executeAndReschedule (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/utils.js:791:9)
        at makeInterruptibleAsyncInterval (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/utils.js:798:9)
        at Monitor.connect (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/monitor.js:87:71)
        at Server.connect (/home/ubuntu/cnox-webbackend/node_modules/mongoose/node_modules/mongodb/lib/sdam/server.js:100:28)
    (Use `node --trace-warnings ...` to show where the warning was created)

I am using aws document db to connect my node application .
I am able to access mongo db using shell so mongodb is fine and access ip whitelisting is fine. Something wrong in the connection .
Please take a look how can i fix this

Note: I am able to connect using shell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方的韩爷 2025-01-29 18:57:34

package.json 文件中查看 mongoose 版本。

使用版本 V6+您不应添加 USENEWURLPARSER UseunifiedTopology 选项,因此您应该删除这些选项。 Mongoose将它们设置为 true 默认情况下。

Check the Mongoose version in the package.json file.

With version v6+ you should not add useNewUrlParser and useUnifiedTopology options, so you should remove these options. Mongoose will set them to true by default.

小忆控 2025-01-29 18:57:34

你能尝试一下吗?

mongoose.connect('mongodb://<user>:<pass>@cnox-beta-document-db.cluster-cvzxy5kwx8pn.us-west-2.docdb.amazonaws.com:27017/cnox?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false', {
  ssl: true,
  sslValidate: true,
  sslCA: `path_to/rds-combined-ca-bundle.pem`
});

参考

PS:您可能需要从最初问题中删除凭据。

Can you try this?

mongoose.connect('mongodb://<user>:<pass>@cnox-beta-document-db.cluster-cvzxy5kwx8pn.us-west-2.docdb.amazonaws.com:27017/cnox?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false', {
  ssl: true,
  sslValidate: true,
  sslCA: `path_to/rds-combined-ca-bundle.pem`
});

Reference.

PS: You might want to remove the credentials from your initial question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文