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