MongoDB Cluster VSCode Connection

140 Views Asked by At

I created a MongoDB cluster. Added my IP Address in the Network Access Tab. Then I went to VSCode and added the Extension for MongoDB. I clicked connect and then I inserted the connection string from my MongoDB cluster which looks like this: (yes I filled the connection string with my informations)

mongodb://<myaccount>:<mypassword>@<mycluster>.mongodb.net/

But when connecting I always get this error:

Unable to connect: getaddrinfo ENOTFOUND <mycluster>.mongodb.net

Additional Info: I have a MacBook.

Is there any additional configuration that I need to make or specific DNS / Firewall configuration?

I tried:

  • pinging my cluster but could also not reach it
  • connecting from MongoDBCompass from there it works
1

There are 1 best solutions below

0
rickenbacker On

First, check if You really have used right IP address to open network access, use below command:

curl -4 ifconfig.co

Then try to use this connection string as You are connecting cluster which is hosted remotely not locally, therefore You are also connecting server not only database:

mongodb+srv://<myaccount>:<mypassword>@<mycluster>.mongodb.net/<your_database_name>?retryWrites=true&w=majority

Remember to recheck Your server url and to put Your database name after server address, it is probably required only when it is not default one (and not required when connecting through MongoDB Compass). Server url and whole connection string can be attained when in MongoDB Atlas You click on Connect option on Your cluster screen.

Here are some docs for reference: https://www.mongodb.com/docs/manual/reference/connection-string/