我正在使用winston库:https://github.com/flatiron/winston尝试使用以下命令将数据存储到mongodb数据库:https://github.com/indexzero/winston-mongodb
插入我使用的数据:
var MongoDB = require('winston-mongodb').MongoDB;
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.MongoDB)({ host: ip, db: 'caribcultivate', collection: 'log', level: 'info'})
], exceptionHandlers: [ new winston.transports.Console() ]
});
logger.log('info', "Running logs "+ d);
logger.info("Drive: "+ (new Date(d)).toDateString());
但是当我尝试使用以下方法查询数据时:
winston.query(options, function (err, results) {
if (err) {console.log(err);}
console.log(results);
});
我明白了:
{}
它适用于控制台,我正在使用Mongoose库的应用程序的其他部分中的数据库 .
2 回答
我遇到了类似的问题 . 事实证明,问题在于Winston MongoDB传输期望主机选项只是主机名,而我在前面加上
mongodb://
.从
mongodb://123456.mongolab.com
删除mongodb://
后,以下内容适用于我:它应该是如此简单,它将在一行中: