Hello, I've got an installation of mongodb 2.6.4 and a databases in it, but having some issues if I use auth = true:
Code:
<?php
$m = new MongoClient("mongodb://user:pass@localhost/mydb");
// $m = new MongoClient("mongodb://localhost:27017/mydb");
$db = $m->selectDB("mydb");
// coll is a collection
$cursor = $db->execute("db.coll.count();");
echo $cursor['retval'];
?>
Running this small PHP code ends up in error:
Code:
[conn2] Unauthorized not authorized on mydb to execute command { $eval: CodeWScope( db.coll.count();, {}), args: [] }
If I use auth = false in mongod.conf and switch to:
Code:
$m = new MongoClient("mongodb://localhost:27017/mydb");
The code works as expected.
I've ran db.createUser(...) and didn't return an error, but still nothing.
Also, if I use the command line command 'mongo' and do:
Code:
$ mongo
use mydb
db.auth("user", "pass")
db.coll.count()
All works.
Am I missing something? How could I fix this, add user 'user' to have proper access on db 'mydb' ?