You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级至Mongoose 8后MongoDB认证失败的问题求助

Mongoose从5.13.7升级到8.15.1后MongoDB认证失败

我正尝试将Express项目的Mongoose版本从5.13.7升级到8.15.1,但现在无法完成MongoDB数据库的认证。

之前可正常运行的代码:

mongoose.connect("mongodb://localhost:3005/", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    user: "mongoAdmin",
    pass: "<password>",
    dbName: "MyTest",
    sslKey : "<contents of my private-key.pem file>",
    sslCert: "<contents of my certificate.pem file>",
});

现在我尝试的所有参数组合都导致认证失败,尤其是以下代码:

mongoose.connect(`mongodb://mongoAdmin:<password>@localhost:3005/MyTest`);

根据文档说明这应该可行,但实际失败了。

我可以通过以下命令行运行mongosh成功连接数据库:

mongosh mongodb://127.0.0.1:3005/MyTest -u mongoAdmin -p '<password>' --authenticationDatabase admin

有人能给我一些提示吗?我已经毫无头绪了。


补充该请求对应的mongod.log日志信息,奇怪的是一次请求生成了两条连续日志,一条成功一条失败:

{"t":{"$date":"2025-05-30T17:47:32.309-07:00"},"s":"I",  "c":"ACCESS",   "id":5286306, "ctx":"conn416","msg":"Successfully authenticated","attr":{"client":"127.0.0.1:39708","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"mongoAdmin","db":"admin","result":0,"metrics":{"conversation_duration":{"micros":10132,"summary":{"0":{"step":1,"step_total":2,"duration_micros":33},"1":{"step":2,"step_total":2,"duration_micros":14}}},"extraInfo":{}}}
{"t":{"$date":"2025-05-30T17:47:32.317-07:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn417","msg":"Failed to authenticate","attr":{"client":"127.0.0.1:39720","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"mongoAdmin","db":"admin","error":"AuthenticationFailed: SCRAM authentication failed, storedKey mismatch","result":18,"metrics":{"conversation_duration":{"micros":17981,"summary":{"0":{"step":1,"step_total":2,"duration_micros":29},"1":{"step":2,"step_total":2,"duration_micros":10}}},"extraInfo":{}}}

内容的提问来源于stack exchange,提问作者One Guy Hacking

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 00:16:04