https://hastebin.com/rubabogumo.cs
==> My code (node:29533) UnhandledPromiseRejectionWarning: TypeError: client.close is not a function
I get this error if I do
const db = new KeyMongo(`mongodb+srv://CORRECT_URL.mongodb.net/test?retryWrites=true&w=majority`,{db:"mongo-test",collection:"keyv"})
db.set("KEY","VALUE").catch(console.error())
You need to call MongoClient.connect() to establish a connection. This method either returns a promise or execute a callback. Depending on how you would like to use KeyMongo class, there are many ways to incorporate connect() in the class.
One way is have another async method to initialise KeyMongo . For example:
const km = new KeyMongo(`MONGODB_URI`, {db:"dbName",collection:"collName"})
km.init(function(){
km.set("Key","Value").catch(console.error())
});
Thank you for providing the code snippet that’s quite useful. If you have further questions, please provide which MongoDB Node.JS driver you are using.