'Error while Connecting MongodB using NodeJs

I'm getting below error, after running npm start command in terminal. ERROR: connecting issue Below is the code:

const uri = process.env.ATLAS_URI;
mongoose.connect(uri);
const connection = mongoose.connection;
connection.on('open', () => {
console.log('Mongoose connected!')
})


Solution 1:[1]

The error indicates that there is no error in the code. This leaves you with three potential possibilities:

  1. Ensure you have MongoDB installed on your computer.
  2. Make sure you're connected to wifi that is not public.
  3. Make sure you have allowed the IP in network access of MongoDB as shown in the image below: https://i.stack.imgur.com/B2aBZ.png

In my case, I was connected to public wifi in a coworking space. I change my connection to my personal hotspot and it worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Boringcoder