(node:44612) DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version

Got this deprecation warning on Node v14.15.3 and Mongo v4.4.3. Is it safe to ignore?

(node:44612) DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version.

14 Likes

@Lauren_Schaefer Is this warning safe to ignore? I too am getting this error with Mongodb version 4.4, Mongoose version ^5.10.12 and Node v12.16.3 Got your reference from the answer Warning: Accessing non-existent property ‘MongoError’ of module exports inside circular dependency

If you are using mongoose version 5.11.16 or a higher version as your ODM. You can solve this issue by downgrading it to version 5.11.15
npm uninstall mongoose
npm i mongoose@5.11.15

learn more here solved stackOverflow

1 Like

Yep, you can ignore this one for now. It’s just warning you that this will be an issue when you upgrade to the next major version.

A little more info from one of the driver engineers:

Db is no longer the place to listen to events, you should listen to your MongoClient instead like so:

const client = new MongoClient(…)
client.on(‘Event name I want to listen too’, () => {…})
await client.connect()

The reason for this style is because by registering your listeners before connecting you can be sure that you’re able to capture every event that is triggered

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.