I have created a cluster on atlas and attempted to connect using my node app and log the connection status with mongoose. I have whitelisted my ip and set everything up properly but I keep getting UnhandledPromiseRejectionWarning.
Here's my code for db.js. Error throws on mongooose.connect(url, opts).
const mongoose = require('mongoose');
const db_connect = async () => {
const conn_string = await mongoose.connect('mongodb+srv://devjoe:
<password_hidden_delibarately>@devcamper-gs1nb.mongodb.net/devcamper?retry
Writes=true&w=majority',
{
useCreateIndex: true,
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true
});
console.log(`connection string: ${conn_string.connection.host}`);
}
module.exports = db_connect;
In server.js file, I just called the function like db_connect(); after importing with commonjs module.
Any help will be appreciated as I can't find what the issue is. Thanks.
db_connect().then(()=>console.log("okay")). catch (()=>console.log(" not okay")) ;db_connect(), just replace with the given code and let me know!