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

 

posted @ 2020-11-08 16:33  星辰ꦿ.大海  阅读(207)  评论(0编辑  收藏  举报