Error in Database Connection

Here is the Error…

> querySrv ECONNREFUSED _mongodb._tcp.nutritionalera.g9ughbo.mongodb.net

Here is the connection code:

`

const mongoose = require(‘mongoose’);

const config = require(‘config’);

const db = config.get(‘mongoURI’);

// mongoose.connect(db);

const connectDB = async () => {

try{

    await mongoose.connect(db, {

        useNewUrlParser: true,

    });

    console.log("Mongo DB is connected")

}catch(err){

    console.error(err.message);

    process.exit(1);

}

}

module.exports = connectDB;

`


“mongoURI”:“mongodb+srv://:nutritionalera.g9ughbo.mongodb.net/?retryWrites=true&w=majority”,

See the possible answer here, and the link therein.

It asks you to go to Atlas and get the long connection string. Seems to work as people can normally connect afterwards (also indicated here Atlas Troubleshooting guide)

If that doesn’t work, continue with this suggestions.

1 Like