我的Mongo Uri是这样的。我的密码末尾必须有@。和Mongo抛出一个错误called=未转义的at-sign在授权部分。有没有办法让它工作呢?
const url = 'mongodb://roots:something@@localhost:27017?authMechanism=DEFAULT&authSource=db';发布于 2020-05-14 19:29:18
尝试使用以下内容对您的用户名和密码进行编码:
function percentEncode(string) {
let encoded = '';
string.split('').forEach(function(char) {
encoded += '%' + char.charCodeAt(0).toString(16).toUpperCase();
});
return encoded;
}https://www.rfc-editor.org/rfc/rfc3986#section-2.1
我的想法是从这里得到的:https://github.com/strongloop/loopback-connector-mongodb/issues/499
好运=)
发布于 2020-05-14 19:34:07
您还可以使用以下模板文字对字符串进行编码:
const DB_USER =‘root’;
const密码= encodeURIComponent('something@');
const DB_URL = mongodb://${DB_USER}:${PASSWORD}@localhost:27017?authMechanism=DEFAULT&authSource=db';
在我看来,它也更容易阅读
希望这会有帮助=)
发布于 2020-05-14 19:47:53
您可以使用URL encoding,@的默认ASCII代码是%40。请参阅链接here
const url = 'mongodb://roots:something%40@localhost:27017?authMechanism=DEFAULT&authSource=db';https://stackoverflow.com/questions/61796163
复制相似问题