无法将日志保存到mongodb数据库以获取winston-nodejs

kyl*_*eED 7 logging mongodb node.js winston

我正在使用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());
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用以下方法查询数据时:

winston.query(options, function (err, results) {
    if (err) {console.log(err);}
    console.log(results);
});
Run Code Online (Sandbox Code Playgroud)

我明白了:

{}
Run Code Online (Sandbox Code Playgroud)

它适用于控制台,我正在使用Mongoose库的应用程序的其他部分中的数据库.

msr*_*thr 5

我遇到了类似的问题。结果证明我的问题是 Winston MongoDB 传输期望主机选项只是主机名,而我在它前面加上了mongodb://.

mongodb://从 中删除后,以下内容对我有用mongodb://123456.mongolab.com

var logger = new(winston.Logger)({
    transports : [
        new(winston.transports.MongoDB)({
            db : 'logs',
            host : '123456.mongolab.com',
            username : 'username',
            password : 'password'
        })
    ]
});
Run Code Online (Sandbox Code Playgroud)