gpt4 book ai didi

node.js - Mongoose 连接 url 显示格式错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:05:23 25 4
gpt4 key购买 nike

使用以下代码进行连接:

mongoose.connect(dbConnection, dbOptions, function (err, res) {
if (err) {
console.log('ERROR connecting to: ' + dbConnection + '. ' + err);
} else {
console.log('Successfully connected to: ' + dbConnection);
}
});

但无法连接并出现以下错误:

URIError: URI malformed

请帮我解决这个问题。提前致谢..

最佳答案

问题是(来自 connection string spec ):

If the username, or password section contains a percent sign ("%"), an at-sign ("@") or a colon (":") it MUST be URL encoded.

If the user information contains an at-sign ("@") or more than one colon (":") then an exception MUST be thrown informing the user that the username and password must be URL encoded.

尝试使用encodeURIComponent()

关于node.js - Mongoose 连接 url 显示格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42392644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com