winstonjs / winston-mongodb

A MongoDB transport for winston
https://github.com/winstonjs/winston-mongodb
296 stars 125 forks source link

Option for useUnifiedTopology #170

Open ben4d85 opened 4 years ago

ben4d85 commented 4 years ago

When using winston-mongodb, I receive the following message in the console:

(node:580) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

The following code solves the issue. However, I was wondering if you would consider adding useUnifiedTopology: true to the default options?

    loggerApp.add(
        new transports.MongoDB({ 
            db: mongoURI,
            options: { useUnifiedTopology: true, }
        }
    ));
helloalexdodd commented 4 years ago

Ran into the same issue. Thank-you @ben4d85 for the solution! At the very least instructions to fix this should be documented somewhere, but agreed that it should be set to a default option.

leodinas-hao commented 4 years ago

The useUnifiedTopology set will impact on the default autoReconnect option. Please find the doc here.

After adding useUnifiedTopology, my question comes: will removing autoReconnect impact logging in any way?

jrebmann commented 3 years ago

After enabling the useUnifiedTopology option, I observed a strange behavior. All my unit tests went wrong.

This was because I sent 8 log messages in my unit test, but after executing a logger.end() only one was written to the database.

As soon as I deactivate the option useUnifiedTopology again, everything runs as desired again.

Can someone help me there? I cannot explain this to myself.