Current URL string parser is deprecated [duplicate]

徘徊边缘 提交于 2019-12-21 07:03:02

问题


when I run the code by "node app.js" command this error is showing

(node:2509) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.


回答1:


You need to pass { useNewUrlParser: true } option to mongoose.connect() method. Your code should look similar to the snippet below.

mongoose.connect('mongodb://user:pw@host1.com:27017/dbname', { useNewUrlParser: true })



回答2:


to avoid this problem use this

MongoClient.connect('mongodb://user:password@sample.com:port/dbname', { useNewUrlParser: true })



回答3:


For those having this message "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. even I didn't mention anything related to promise"

I pasted the code the error gets fixed with in the following link. https://stackoverflow.com/a/52459082/10399142



来源:https://stackoverflow.com/questions/51165536/current-url-string-parser-is-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!