【发布时间】:2020-08-03 03:45:48
【问题描述】:
MongoError: database name must be a string
Nodejs 脚本:
// Azure tells me to use mongodb://mydb:LONG-STRING-ENDING-WITH==@mydb.documents.azure.com:10255/?ssl=true
// I change the = to %3D - I've confirmed this is the correct escaping
readonly serverConnection = 'mongodb://mydb:LONG-STRING-ENDING-WITH%3D%3D@mydb.documents.azure.com:10255/?ssl=true');
...
const mongoDB = await mongoose.connect(
this.serverConnection,
{
useNewUrlParser: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000
}
);
如果我删除 == 或 %3D%3D,或更改为其他内容(例如 XX),则错误是预期的:
{ MongoError: Authentication Failed
所以不是字符串的长度,必须是==。
为什么会这样?可以做些什么来解决这个问题?
【问题讨论】:
-
我遇到了同样的问题...我从 azure 门户复制了节点的显式连接字符串,但它不起作用。我希望有人能解释为什么会这样!