MongoConnectionException - Failed to connect to: localhost:27017

user10 picture user10 · Jan 8, 2013 · Viewed 19.5k times · Source

I used the following PHP code to connect to MongoDB:

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

However, I am getting the following error:

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: Unknown error'

I tried lot of connection string possibilities that are posted in various blogs; nothing helps. Does anyone have any ideas?

Answer

user10 picture user10 · Jan 9, 2013

If anybody has this issue, refer the following links first.

Connection String URI Format

PHP MongoClient

In my case McAfee firewall leads to this problem. When i 'Turn-Off' firewall it started working..