在连接MongoDB数据库时,去除Node中提示的碍眼东西

在连接MongoDB数据库时,去除Node中提示的碍眼东西:

第一个:

(node) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

第二个:

(node) 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.

第三个:

(node) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes

解决方法:

// 引入mongoose第三方模块
const mongoose = require('mongoose');
// 连接数据库
mongoose.set('useCreateIndex', true) ;//解决第三个
mongoose.connect('mongodb://localhost/blog', {useNewUrlParser: true ,useUnifiedTopology: true})//解决第一个和第二个
	.then(() => console.log('数据库连接成功'))
	.catch(() => console.log('数据库连接失败'));
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页