这是我用来将“someuser”用户添加到“someusersdatabase”的php代码。
<?
// open connection
$mongo = new Mongo("mongodb://admin:passwd@remotemongoserver:27017");
$db = $mongo->selectDB("someusersdatabase");
$mongo->selectDB("someusersdatabase")->createCollection('__tmp_collection_');
$mongo->selectDB("someusersdatabase")->dropCollection('__tmp_collection_');
// $collections = $db->selectCollection("tmp");
// $collections->insert(array('t' => '1'));
// user info to add
$username = "someuser";
$password = "apassword";
// insert the user - note that the password gets hashed as 'username:mongo:password'
// set readOnly to true if user should not have insert/delete privs
$collection = $db->selectCollection("system.users");
$collection->insert(array('username' => $username, 'pwd' => md5($username . ":mongo:" . $password), 'readOnly' => false));
我可以作为管理员进行身份验证,但是当我验证某些用户时,日志会显示:
Mon Jun 27 14:01:38 [initandlisten] connection accepted from client:62708 #1
Mon Jun 27 14:01:38 [conn1] auth: couldn't find user someuser, someusersdatabase.system.users
但是当我导航到Web视图时,它会显示someusersdatabase和someusersdatabase.system.users
用户没有正确添加? php代码运行时没有抛出任何错误......