MongoConnectionException - Failed to connect to: localhost: 27017

I used the following PHP code to connect to MongoDB:

$m = new MongoClient("mongodb://localhost:27017"); 

However, I get the following error:

Fatal error: Failed to throw "MongoConnectionException" with the message "Could not connect to: localhost: 27017: Unknown error"

I have tried many connection string features that are hosted on different blogs; nothing helps. Does anyone have any ideas?

+4
source share
1 answer

If anyone has this problem, please provide the following links first.

Connection string URI format

PHP MongoClient

In my case, the McAfee firewall is causing this problem. When I turned on the firewall, it started working.

+2
source

All Articles