当我运行"node app.js"命令时,会出现以下错误:(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.
{ useNewUrlParser: true }
选项。你的代码应该类似于下面的片段。mongoose.connect('mongodb://user:pw@host1.com:27017/dbname', { useNewUrlParser: true })
url
和callback
之间作为第二个参数传递{useNewUrlParser:true}时,我遇到了相同的错误。 - Phillip BergerMongoClient.connect('mongodb://user:password@sample.com:port/dbname', { useNewUrlParser: true })
对于那些出现“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”这个消息的人,即使我没有提及与promise有关的任何内容。
我将代码粘贴在以下链接中,错误已被修复。 https://stackoverflow.com/a/52459082/10399142