1
votes

I'm connecting to a mongoose db, and I get a deprecation warning every time I try to connect.

(node:14933) 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.

I set useUnifiedTopology to true but I'm still getting the error. What am I doing wrong and how can I fix it?

const mongooseOptions = {
    useNewUrlParser: true,
    useCreateIndex: true,
    useFindAndModify: false,
    useUnifiedTopology: true,
};

const dbUrl = config.get('dbUrl');

await mongoose.connect(dbUrl, mongooseOptions);
1
Looks correct to me. Does the mongo URL include any *reconnect* options? Could there be anywhere else a connection is made from?Matt
@Matt your right! I'm using agenda: const agenda = new Agenda({ db: { address: dbUrl }, processEvery: '1 seconds', }); shud i be using the same connection?Jessica
Yeah, or at least adding the same options.Matt

1 Answers

0
votes

The DeprecationWarning for useUnifiedTopology comes from the underlying mongodb driver. Any connections will need this setting to use the new connection management.

In agenda, pass in options:

const agenda = new Agenda({
  db: {
    address: 'mongodb://localhost:27017/agenda',
    options: {
      useUnifiedTopology: true,
      useNewUrlParser: true,
    }
  }
})

It looks like agenda can also reuse an existing mongoose connection by passing in the underlying mongodb db, something like:

const agenda = new Agenda({
  mongo: mongoose.connection.db('agenda-test')
})