关于警告 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}。
var MongoClient = require('mongodb').MongoClient var url = 'mongodb://localhost:27017/testdb'// 数据库地址 module.exports = { getDB: function (callback) { MongoClient.connect(url, {useNewUrlParser:true}, function (err, db) { callback(db) }) } }