How do I properly connect via a php script to a local windows
mongodb database, which has a username/password setup for it? It seems pretty simple, but the following code does not work.
- Using robomongo as my gui admin I created a database called "ezr". Then I created a user called "ezr" with a password of "test" and gave this user all permissions.
- Then I restarted mongod.exe --auth. Remember I'm on windows. From the docs this should allow for mongodb to accept connection with auth info.
- PHP has the mongo extension installed and I've tested connecting to my local mongodb to a database without auth info and it works just fine. I can create collections, insert documents, etc.
Here's my php code: $conn = new MongoClient('mongodb://ezr:test@localhost/ezr');
- Here is the exception error message php gives me: Failed to connect to: localhost:27017: Authentication failed on database 'ezr' with username 'ezr': auth failed
- From the command liine when I connect to mongo, these are the results:
MongoDB shell version: 2.6.3
Enter password:
{I enter "test" here}
connecting to: ezr
2014-07-21T16:16:05.649-0700 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 1
8 } at src/mongo/shell/db.js:1210
exception: login failed
Again, seems so simple. In mysql it is beyond easy to setup a user and roles, what am I missing here with mongodb on a local windows dev setup when trying to setup a user on a database?