DeprecationWarning: current URL string parser is deprecated, and will be removed in a future vers...

问题

  1. node连接Mongoose时抛出了两个DeprecationWarning(弃用警告):
(node:61084) 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.
// 弃用警告:当前的URL字符串解析器已弃用,并且在将来的版本中会移除该功能。要用新的解析器,需要在调用MongoClient.connect是传参:{ useNewUrlParser: true }
(node:61084) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
// 弃用警告:当前的Server Discovery和Monitoring engine已弃用,并且在将来的版本中会移除该功能。要用新的Server Discover和Monitoring engine,需要在调用MongoClient.connect是传参:{ useUnifiedTopology: true }

解决

- MongoClient.connect(yourUrl)
+ MongoClient.connect(yourUrl, { useNewUrlParser: true, useUnifiedTopology: true })
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。