cappedMax not working in winston-mongodb logger in Node.js on Ubuntu

亡梦爱人 提交于 2019-12-12 03:36:58

问题


I have created a logger in Node.js using the winston module and added MongoDB transport by requiring winston-mongodb module with the following options:

{
  db: config.db[k.DB_ENV.AUTHOR],
  username: config.dbUser,
  password: config.dbPassword,
  collection: 'log-aggregation',
  storeHost: true,
  capped: true,
  cappedMax: 10 // documents
}

I expect the logger to create a new collection for every 10 documents. But the logger continue logging in the same collection. I commented the collection: 'log-aggregation' line to check if the options are really working and then it began to log to the default 'log' collection.

So where is my mistake? Is there a minimum no of document size to the cappedMax option? I tried this with cappedSize option also with 10 to 1000 values, still the new collections are not created.

I want to know the minimum and maximum permissible value for cappedSize and cappedMax option?

I also want to know what will be the name of new collections created?


回答1:


This is what I use to get multiple logs:

var winston = require('winston');
require('winston-mongodb').MongoDB;


winston.loggers.add('userLog',{
    transports : [
        new(winston.transports.MongoDB)({
            db : 'mongodb://username:password.mongolab.com:5555/log_db',
            collection : 'userLog',
            capped : true
        }),
    ]
});
winston.loggers.add('profileLog',{
    transports : [
        new(winston.transports.MongoDB)({
            db : 'mongodb://username:password.mongolab.com:5555/log_db',                collection : 'profileLog',
            capped : true
        }),
    ]
});

And it works fine with no observable latency.

P.S. You can add all the options you want after or before capped:true

Have fun!



来源:https://stackoverflow.com/questions/34511857/cappedmax-not-working-in-winston-mongodb-logger-in-node-js-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!