连接数据库的时的错误提示: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.

从截图可以看到服务器是连接成功的,如果想要去掉这段警告,需要在连接数据库的时候加入划横线的两个参数。

// 引入mongoose第三方模块
const mongoose = require('mongoose');

// 创建数据库
mongoose.connect('mongodb://localhost/books', { useNewUrlParser: true, useUnifiedTopology: true })
    .then(() => {
        console.log('数据库连接成功');
    }).catch(err => console.log(err, '数据库连接失败'));

加完之后就不会有这种警告了。

posted @ 2021-07-05 14:13  前端小白加油  阅读(985)  评论(0)    收藏  举报