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
