这是我用来将用户“某个用户”添加到“某个用户数据库”的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.system.users
那么,是否没有正确添加用户?当php代码运行时没有抛出错误...
发布于 2011-06-28 02:43:26
你可能应该使用call addUser(),而不是直接插入到集合中,以防有一些秘密的记账和/或哈希函数不同。除此之外,字段名是user,而不是username。
https://stackoverflow.com/questions/6497306
复制相似问题