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?
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!