无法从节点连接AWS文档DB
这是我的node.js代码连接文档db的代码。我也有SSL文件。我能够从蒙古尔(Mongoshell)连接,但无法从node.js应用程序连接,
var mongoose = require("mongoose");
//db connection
const dbConnect = require("./dbConnection.js");
const globalErrorMiddleware = require("./middlewares/appErrorHandler");
mongoose.connect(
"mongodb://lbw:dkdDKsKsl@dev-docdb-cluster-1.cluster-ct090j7ac20n.us-east-1.docdb.amazonaws.com:27017/cnox?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false",
process.env.ENV === "LIVE"
? {
ssl: true,
sslValidate: true,
sslCA: `rds-combined-ca-bundle.pem`,
}
: {}
);
我在连接到DB时的错误低于错误。请看看
app listening on port: 5600
/home/ubuntu/cnox-webbackend/node_modules/mongodb/lib/cmap/connection.js:203
callback(new error_1.MongoServerError(document));
^
MongoServerError: Authorization failure
at Connection.onMessage (/home/ubuntu/cnox-webbackend/node_modules/mongodb/lib/cmap/connection.js:203:30)
at MessageStream.<anonymous> (/home/ubuntu/cnox-webbackend/node_modules/mongodb/lib/cmap/connection.js:63:60)
at MessageStream.emit (node:events:527:28)
at MessageStream.emit (node:domain:475:12)
at processIncomingData (/home/ubuntu/cnox-webbackend/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
at MessageStream._write (/home/ubuntu/cnox-webbackend/node_modules/mongodb/lib/cmap/message_stream.js:28:9)
at writeOrBuffer (node:internal/streams/writable:390:12)
at _write (node:internal/streams/writable:331:10)
at MessageStream.Writable.write (node:internal/streams/writable:335:10)
at TLSSocket.ondata (node:internal/streams/readable:777:22) {
ok: 0,
operationTime: Timestamp { low: 1, high: 1652288522, unsigned: true },
code: 13,
[Symbol(errorLabels)]: Set(0) {}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在使用MongoDB JavaScript客户端时遇到了一个非常相似的问题。与其他一些客户端相比,Mongo Shell对服务器配置更宽容。
您可以尝试几件事:
directConnection = true
添加到连接字符串。authsource = CNOX
https://mongodb.github.io/node-mongodb-native/2.2/tutorials/connect/authenticatikating/
另一个猜测是您成功地连接,但是代码是代码正在尝试未经授权的东西。就像尝试与
cnox
以外的其他数据库进行交互或运行当前用户权利不支持的命令。I was running to a very similar problem with using the mongodb javascript client. The mongo shell is much more forgiving to the server configuration than the some of the other clients.
There a couple of things you can try:
directConnection=true
to your connection string.authSource=cnox
https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/#direct-connection
https://mongodb.github.io/node-mongodb-native/2.2/tutorials/connect/authenticating/
Another guess is that you are successfully connecting but then the code is trying to something that isn't authorized. Like trying to interact with another database other than
cnox
or running a command that isn't supported by the current user rights.