mongoose报错 DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead
也不知道为什么报这个错误,网上查找的解决方法,加一行代码解决
命令行工具会提示如下信息:
DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead
解决方法:
//在连接数据库之前加上如下代码
mongoose.set('useCreateIndex', true)
// 连接数据库
mongoose.connect('mongodb://localhost/blog', { useNewUrlParser: true, useUnifiedTopology: true })
星辰ꦿ.大海