我正在学习 Wes Bos 的教程 Learn Node.js。
我下载了所有入门文件并使用 MongoDb Atlas 创建了一个数据库。
当我运行 npm start 时出现此错误:
UnhandledPromiseRejectionWarning: Error: URI does not have hostname, domain name and tld
DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我正在使用环境变量连接到数据库
mongoose.connect(process.env.DATABASE);
变量看起来像这样:
DATABASE=mongodb+srv://<username>:<password>@cluster1-rgvum.mongodb.net/test?retryWrites=true
出于显而易见的原因,我省略了我的用户名和密码。如果有人知道如何进行,将不胜感激!谢谢。
最佳答案
是的,因为密码中使用了特殊字符,要么使用上面的复杂代码进行编码,要么使用这种简单的方法。
在密码中使用十六进制代码而不是您在密码中使用的符号,就像您的文本密码是:- pass123#
所以像这样使用它:- pass123%23
从此处获取 ASCII 代码并使用十六进制代码:- https://ascii.cl/
关于javascript - UnhandledPromiseRejectionWarning : Error: URI does not have hostname, 域名和顶级域名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55445043/