Failed to connect to cluster using a env file

Hello everyone, I am following this YouTube Video guide
here. All steps up to connecting to the Mongo DB work. Ive turned off my Laptop’s firewall, and my my router’s firewall, allowed all IPs on MongoDB, still no working connection. I constantly get the below error:

MongoError: failed to connect to server [] on first connect [Error: getaddrinfo ENOTFOUND
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
  name: 'MongoError'
}] did not connect
[nodemon] clean exit - waiting for changes before restart

For the life of me I cannot seem to get anything to work. I cannot ping the cluster, I have tried 4 different wifi networks, phone hotspot, liabry internet, home wifi, work wifi, and nothing! I’ve disabled my mac’s firewall to try to get it to work, port forwarded “1337”, “27016”, “27017”.
Below is a copy of my code I want to work:

import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";
import helmet from "helmet";
import morgan from "Morgan";
import dotenv from "dotenv";
/* Configurations (mainly used as a boiler plate to config these packages in the long run m*/
const app = express();
app.use(helmet.crossOriginResourcePolicy({ policy: "cross-origin" }));
app.use(bodyParser.urlencoded({ extended: false }));

console.log("Hello World");
/* Mongoose SETUP */
const PORT = process.env.PORT || 9000;
console.log("Port from ENV", PORT);

    .connect(process.env.MONGO_URL, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
    .then(async () => {
        app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));
    .catch((error) => console.log(`${error} did not connect`));

Below is a copy of my .env file, with sensitive info removed for this forum:


Hi @James_Coates

MongoDB Atlas URIs are mongodb+srv:// try updating the connection string to begin with than instead of mongodb://

1 Like

this has been fixed by MongoDB support messages, now I have a new issues regarding: MongoError: (Unauthorized) not authorized on admin to execute command { dropDatabase: 1, writeConcern: { w: “majority” } } did not connect.

I have ensured that on the MongoDB website all user permissions are set to readwrite all database but still no luck


dropDatabase is not a privilege granted by readWrite all, the dbAdmin role will grant the necessary privilege. If dbAdmin grants more privileges than desired creating a custom role is another option.