Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在蒙古里,我如何处理@ ;在我的密码里?_Node.js_Mongodb - Fatal编程技术网

Node.js 在蒙古里,我如何处理@ ;在我的密码里?

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

我的Mongo Uri是这样的。我的密码末尾必须有一个@。Mongo在登录权限部分抛出一个名为=Unescaped的错误。有没有办法让它发挥作用

 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倍??