MongooseError [MongooseServerSelectionError]: getaddrinfo EAI_AGAIN – How to fix?
In this small post, let’s see how to resolve getaddrinfo EAI_AGAIN error when you try to connect to a database in mongo using Mongoose or other mongo libraries.
This error probably occurs because your Mongo DB connection URI is wrong.
“mongodb://appuser:app@123!@localhost:27017/appdb”
Let’s consider the above Mongo connection URI that you use to connect to your Mongo Database.
If you get getaddrinfo EAI_AGAIN error when you connect to your database, please check the following.
- If username and password are correct
- The Mongo URL is in the correct format. i.e. mongodb://username:password@host:port/db
- The host is accessible and your network connectivity is good.
- You have the specified database in mongo.