couldn’t connect to server 127.0.0.1:27017 ,Today in this article we will cover basic steps to resolve the error MongoDB
Today in this article, we will cover below aspects,
Mongo connection using shell command or using Mongo Atlas UI portal gives below error,
Error: couldn't connect to server localhost:27017, connection attempt failed: SocketException: Error connecting to localhost:27017 (127.0.0.1:27017) :: caused by :: No connection could be made because the target machine actively refused it. : connect@src/mongo/shell/mongo.js:372:17 @(connect):2:6 exception: connect failed exiting with code 1 'ssl' is not recognized as an internal or external command, operable program or batch file.
Please use the below steps to verify the issue,
- Recheck your connections string.
- Make sure you use correct command for the connection
- Example : mongo mongodb://localhost:27017/?readPreference=primary&ssl=false
As indicated above your command should append with mongo followed by a connection string.
Once verified, please cross-check if the MongoDB service is running on your machine.
Use the below command to run the MongoDB service,
sc start mongodb
Alternatively, you can use Service Control Manager (SCM) to start or restart the service if running already.
You could try the below command to start the MongoDB service for Ubuntu/Linux
sudo service mongodb status sudo service mongodb start
Other references : couldn’t connect to server 127.0.0.1:27017
That’s all! Happy coding!
Does this help you fix your issue?
Do you have any better solutions or suggestions? Please sound off your comments below.
See More: SQL Check if table exists
Add a column with a default value to an existing table in SQL