代码点火器错误无法连接到MongoDB:连接失败:身份验证失败


Codeigniter error Unable to connect to MongoDB: Failed to connect: auth failed

我正在尝试使用codeigniter mongob库Codeigniter-mongo-library-master连接到mongodb数据库"考试"。我已经为此数据库创建了一个用户,使用

db.createUser({ user: "root",
  pwd: "root",
  roles: [
    { role: "readWrite", db: "exam" },
   ]
}}

它很成功。

然后,当我尝试在代码点火器中使用以下方法连接到此数据库时:

$config['mongo_db']['default']['no_auth'] = FALSE;
$config['mongo_db']['default']['hostname'] = 'localhost';
$config['mongo_db']['default']['port'] = '27017';
$config['mongo_db']['default']['username'] = 'root';
$config['mongo_db']['default']['password'] = 'root';
$config['mongo_db']['default']['database'] = 'exam';

我收到如下所示的错误:

无法连接到MongoDB:无法连接到:本地主机:27017:用户名为"root"的数据库"考试"身份验证失败:身份验证失败。

我在Windows 5.5.12

上使用php版本5.5.12和mongodb驱动程序php_mongo-1.5.1-5.5-vc11-x86_64.dll。

我可以得到一些帮助来解决这个问题吗?

尝试更改此变量的值:

$config['mongo_db']['默认']['no_auth'] = 假

$config['mongo_db']['默认']['no_auth'] = 真

现在打开控制器或模型文件,其中需要另一个数据库连接处于活动状态,并在类的构造函数中编写以下代码。

$this->load->library('mongo_db', array('activate'=>'newdb'),'mongo_db2');