我在使用以下代码时遇到了问题:
$m = new MongoClient('mongodb://sf:xxxxxx@localhost/sf');
$collections = $m->selectDB("sf")->getCollectionNames();
var_dump($collections); // prints collection names as expected
$collections = $m->selectDB("sf")->execute('function (){ return db.getCollectionNames(); }');
var_dump($collections); // gives error "unauthorized"此内容已在以下位置转载:
Mongo 2.4.0,MongoDB PHP驱动程序1.3.6,PHP版本5.3.8,Windows7 32位
MongoDB 2.4.0,PHP驱动1.3.5,PHP版本5.3.2,ubuntu10.04.4
有什么帮助吗?
发布于 2013-03-29 07:54:02
PHP的execute只是一个用来调用eval的包装器,它需要管理员权限才能使用。
从文档中:
With authentication enabled, eval will fail during the operation
if you do not have the permission to perform a specified task.
Changed in version 2.4: You must have full admin access to run.发布于 2013-09-23 08:50:10
检查MongoDB的连接字符串。如果它包含数据库,请尝试删除它。例如:
mongodb://sf:pass@localhost/sf
至
mongodb://sf:pass@localhost/
完成此操作后,请在使用身份验证实例化客户端后选择数据库。我相信这应该可以让你使用这个函数。我相信这会导致对admin集合而不是指定的集合进行身份验证,这可能会提供对此函数的访问。
https://stackoverflow.com/questions/15694165
复制相似问题