MongoServerSelectionError: connection <monitor> to 13.235.142.61:27017 closed

MongoServerSelectionError: connection to 13.235.142.61:27017 closed

Getting Authentication failed error.
‘mongodb+srv://Mahesh:12345@cluster0.4fbnl.mongodb.net/meetups?retryWrites=true&w=majority’

Thanks in advance.

from a console, your connection string has this error; it is not an accesible address.

getaddrinfo("cluster0.4fbnl.mongodb.net") failed: No address associated with hostname
Error: couldn't initialize connection to host cluster0.4fbnl.mongodb.net, address is invalid

other than that, your username/password might have a typo, you might be forgetting auth admin database, or tls/ssl flags.

try your connection string in a terminal with mongo, mongosh, or use Compass. if you connect succesfuly with them, you can then use it in your app

you seem you are still in beginner’s steps. if not, sorry for the impression.

let me suggest you 2 things for you to work with MongoDB and Javascript.

1- Run a local MongoDB server. This will be both faster during development and easy to setup.

  • Download a zipped version of the community server. MongoDB Community Download
  • extract it to some folder, I have mine in c:\DevTools\mongodb
  • create a data folder, preferably in the same folder c:\DevTools\mongodb
  • run with c:\DevTools\mongodb\bin\mongod.exe --dbpath c:\DevTools\mongodb\data
  • create a batch file with this line in it on desktop, or in a place where you most work, maybe in your project directory.
  • connect to it with MongoClient.connect("mongodb://127.0.0.1")

2- If you haven’t done so, check this course: M220JS: MongoDB for JavaScript Developers | MongoDB University.

Means you have the wrong user name or the wrong password.

There is no DNS address since this is a cluster address. There is TXT DNS entry and corresponding SRV record.

id 62723
opcode QUERY
rcode NOERROR
flags QR RD RA
;QUESTION
cluster0.4fbnl.mongodb.net. IN TXT
;ANSWER
cluster0.4fbnl.mongodb.net. 44 IN TXT "authSource=admin&replicaSet=atlas-x8f8fc-shard-0"
;AUTHORITY
;ADDITIONAL