Donald Zhu
Donald Zhu

Reputation: 855

How to not create a new MongoDB collection with winston?

I am new to node.js and I am trying to use the node package winston-mongodb to log my messages to the database: winston.add(new winston.transports.MongoDB({db: 'mongodb://localhost/myProject'}))But if I start the application again, I run into this problem in the terminal: winston-mongodb, initialization error: MongoError: Collection already exists.

The person whose tutorial I am following didn't seem to have this problem. Is it possible to tell winston that, if the collection already exists, simply write to it instead of creating a new one?

Upvotes: 1

Views: 681

Answers (1)

D. SM
D. SM

Reputation: 14480

This appears to be a known issue.

To work around, you can create to MongoDB URI yourself and drop the collection (ignoring errors if it doesn't exist) prior to using winston.

Upvotes: 2

Related Questions