Hey. I’m working on a backend system that includes multiple node.js files. It means that in each of the files using MongoDB, I have to open a new connection using MongoClient.connect()
.
But the thing is, that MongoDB doesn’t really seem to like it: I got multiple deprecation errors in the console:
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
[sometimes more]
So my question is: How can I open only 1 connection, so I can use it in all my files? Since the code looks like that
MongoClient.connect((err) => { // err handling
// code using the database
});
not like that
MongoClient.connect((err) => /* err handling */)
// code using the database
I can’t figure out how to find an answer.
Thanks in advance for your help.