我试图向 mongoDB 添加授权。
我使用 mongodb 2.2.4、php-mongo 1.4.1 stable、apache2、php 5.4、ZendFramework 1.12 + ShantyMongo
我也使用带有 3 个实例的副本集。
当我设置 auth = true mongo create admin 数据库时,当我将用户添加到这个数据库时,我得到了这个错误:
Fatal error: Uncaught exception 'MongoCursorException' with message 'test.server.com:27017: unauthorized db:database_test ns:database_test.options lock type:0 client:127.0.0.1' in /apps/test_app/libs/Shanty/Mongo/Collection.php:3501
如果我将用户添加到我的 database_test 一切正常。
<?php
/* Configure logging */
MongoLog::setModule( MongoLog::ALL );
MongoLog::setLevel( MongoLog::ALL );
$m = new MongoClient(); // connect
$db = $m->selectDB("database_test");
$db->authenticate('admin','12345');
即使我将用户添加到 admin 和 database_test,此代码也可以正常工作。
也许有人有类似的问题并且知道我需要做什么。