eatinasandwich
eatinasandwich

Reputation: 636

winston-mongodb error after initializing

I'm trying to configure a basic winston logger but keep getting the same error.

All I have so far to configure it is this

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

var logger = new (winston.Logger)();
logger.add(mongoLog, {
   db: appSettings.database,
   host: appSettings.dbConnection,
   collection: appSettings.loggingCollection
 }
);

This is the error I'm getting.

winston-mongodb: error initialising logger Error: invalid schema, expected mongodb

The host is the ip of a mongodb instance in azure, but that doesn't seem to be the issue because if I remove host (defaulting it to localhost according to the docs) and try to have it connect to my local mongo instance it gives the same error. It also doesn't seem to matter if I call any methods on the logger or not.

Upvotes: 2

Views: 3368

Answers (1)

eatinasandwich
eatinasandwich

Reputation: 636

Was looking at the wrong documentation I guess? On this page it has the db param described like this

db: The name of the database you want to log to.

So I thought I would have the db name there and would need to specify the host separately.

But on this page it has a different description.

db: MongoDB connection uri, pre-connected db object or promise object which will be resolved with pre-connected db object.

Which apparently was the correct description, the full URI being this format:

mongodb://<host>:<port>/<db>

Upvotes: 1

Related Questions