使用以下代码启动数据库,会提示报错信息:
mongoose.connect('mongodb://localhost/playStudent', )
.then(() => console.log('数据库连接成功!'))
.catch(() => console.log('数据库连接失败!'));
解决办法:
在mongoose.connect
中添加参数:{ useUnifiedTopology: true, useNewUrlParser: true }
mongoose.connect('mongodb://localhost/playStudent', { useUnifiedTopology: true, useNewUrlParser: true })
.then(() => console.log('数据库连接成功!'))
.catch(() => console.log('数据库连接失败!'));
成功解决!