I work on a project whose code is divided into multiple js files. Until now, I 've been calling MongoClient.connect()
multiple times (in each file using the db). That's when I got multiple deprecation warnings:
the options [servers] is not supported
the options [caseTranslate] is not supported
the options [dbName] is not supported
the options [srvHost] is not supported
the options [credentials] is not supported
I quickly found out it was related to all these open connections. Even though I can store MongoClient in a separate file, how can I store MongoClient.connect()
, since a code that uses the database looks like that:
MongoClient.connect((err) => {
// code here
});
and not like that:
MongoClient.connect()
// code here