Node.js 在蒙古里,我如何处理@ ;在我的密码里?
我的Mongo Uri是这样的。我的密码末尾必须有一个@。Mongo在登录权限部分抛出一个名为=Unescaped的错误。有没有办法让它发挥作用Node.js 在蒙古里,我如何处理@ ;在我的密码里?,node.js,mongodb,Node.js,Mongodb,我的Mongo Uri是这样的。我的密码末尾必须有一个@。Mongo在登录权限部分抛出一个名为=Unescaped的错误。有没有办法让它发挥作用 const url = 'mongodb://roots:something@@localhost:27017?authMechanism=DEFAULT&authSource=db'; 请尝试使用以下代码对用户和密码进行编码: function percentEncode(string) { let encoded = ''; s
const url = 'mongodb://roots:something@@localhost:27017?authMechanism=DEFAULT&authSource=db';
请尝试使用以下代码对用户和密码进行编码:
function percentEncode(string) {
let encoded = '';
string.split('').forEach(function(char) {
encoded += '%' + char.charCodeAt(0).toString(16).toUpperCase();
});
return encoded;
}
以下是我的想法来源:
好运=)尝试用以下代码对用户和密码进行编码:
function percentEncode(string) {
let encoded = '';
string.split('').forEach(function(char) {
encoded += '%' + char.charCodeAt(0).toString(16).toUpperCase();
});
return encoded;
}
以下是我的想法来源:
Good Luck=)您还可以使用如下模板文本对字符串进行编码: const DB_USER='根' const PASSWORD=encodeURIComponent('something@') const DB_URL=
mongodb://${DB_USER}:${PASSWORD}@localhost:27017?authMechanism=DEFAULT&authSource=DB';
在我看来,它也更容易阅读
希望有帮助=)您也可以使用如下模板文本对字符串进行编码: const DB_USER='根' const PASSWORD=encodeURIComponent('something@') const DB_URL=
mongodb://${DB_USER}:${PASSWORD}@localhost:27017?authMechanism=DEFAULT&authSource=DB';
在我看来,它也更容易阅读
希望它有帮助=)您可以使用
URL编码
,@
的默认ASCII
代码是%40
。参见链接
您可以使用
URL编码
,@
的默认ASCII
代码是%40
。参见链接
你为什么需要2倍?你为什么需要2倍??