1安装mongoose
npm install mongoose
安装成功
2.打开数据库
mongod --path E:mongo
成功
创建一个db.js
var mongoose = require('mongoose'); mongoose.connect('mongodb://127.0.0.1:27017/whhhh', { useMongoClient: true }); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function (callback) { console.log("数据库成功连接"); });
注意:
useMongoClient: true
必须加否则报错
效果:
2017-11-01 23:04:39