nodejs使用mongoose模块链接数据库
//作用链接数据库
const mongoose = require("mongoose");
mongoose.set('useCreateIndex', true)
mongoose.connect(
"mongodb://adminroot:xxxxx@xxxxxxx:27017/blog?authSource=admin",
{ useNewUrlParser: true, useUnifiedTopology: true }
);
mongoose.connection.on('error', () => {
console.log('连接数据库失败')
});
mongoose.connection.on('open', () => {
console.log('链接数据库成功')
});
module.exports = mongoose