Mongoose是MongoDB的一个对象模型工具,是基于node-mongodb-native开发的MongoDB nodejs驱动
调试模式:
查看mongoose模块对mongodb操作的日志
更好的了解和优化对mongodb的操作
var mongoose = require("mongoose"); mongoose.set('debug', true); var db = mongoose.connect("mongodb://127.0.0.1:27017/abc"); db.connection.on("error", function (error) { console.log("数据库连接失败:" + error); }); db.connection.on("open", function () { console.log("数据库连接成功"); });
输出
Mongoose: goods.createIndex({ goodid: 1 }, { background: true }) Mongoose: goods.find({ goodid: { '$in': [ '123456' ] } }, { projection: {} })
设置颜色且格式化输出
var colors = require('colors'); var mongoose = require("mongoose"); mongoose.set('debug', function (collectionName, method, query, doc) { console.log('Mongoose: '.cyan + collectionName + '.' + method + ' (' + JSON.stringify(query, null, 2) + ')'); }); var db = mongoose.connect("mongodb://127.0.0.1:27017/abc"); db.connection.on("error", function (error) { console.log("数据库连接失败:" + error); }); db.connection.on("open", function () { console.log("数据库连接成功"); });
输出
Mongoose: goods.createIndex ({ "goodid": 1 }) Mongoose: goods.find ({ "goodid": { "$in": [ "123456" ] } })
Mongoose颜色设置为青色cyan,也可以尝试下red等