javascript - UnhandledPromiseRejectionWarning : Error: URI does not have hostname, 域名和顶级域名

标签 javascript node.js mongodb mongoose

我正在学习 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/

更多详细信息:- https://docs.atlas.mongodb.com/troubleshoot-connection/#special-characters-in-connection-string-password

关于javascript - UnhandledPromiseRejectionWarning : Error: URI does not have hostname, 域名和顶级域名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55445043/

相关文章:

javascript - 破解 window.location.replace 的行为,使用 javascript 而不是 URL

node.js - Mongoose 查询以增加项目数组中的字段(如果存在),否则将其添加到文档中(很难表述此标题)

java - springboot 应用程序在 Angular 上出现 fsevents 错误

node.js - 在 Mongoose 中的对象内创建对象后复制对象(MongoDB、Node.JS、express)

mongodb - 在mongoDB中通过_id搜索效率更高吗?

javascript - 在闭包中使用 _gaq asynch

javascript - 如何获取google搜索的结果?最好是Json

javascript - 从下拉列表中选择项目时的 Firebug 行为

javascript - Javascript中promise和@@iterator的问题

json - 如何使用 Spring Boot 在 Mongo 中存储原始 JSON