问题
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