我使用Codeigniter MVC。我安装了MongoDB,但它不工作。
Unable to connect to MongoDB: Failed to connect to: localhost:27017: SASL Authentication failed on database 'teknikserviscim': Authentication failed.
配置文件如下;
$config['mongo_db']['active'] = 'newdb';
$config['mongo_db']['newdb']['hostname'] = 'localhost';
$config['mongo_db']['newdb']['port'] = '27017';
$config['mongo_db']['newdb']['username'] = 'superuser';
$config['mongo_db']['newdb']['password'] = '12345678';
$config['mongo_db']['newdb']['database'] = 'teknikserviscim';
$config['mongo_db']['newdb']['db_debug'] = TRUE;
$config['mongo_db']['newdb']['write_concerns'] = (int)1;
$config['mongo_db']['newdb']['journal'] = TRUE;
$config['mongo_db']['newdb']['read_preference'] = NULL;
$config['mongo_db']['newdb']['read_preference_tags'] = NULL;
class PanelHesap extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->library('mongo_db', array('activate'=>'newdb'),'mongo_db2');
}
。问题是什么?谢谢。
您的数据库连接应该是
$config['mongo_db']['active'] = 'default';
$config['mongo_db']['default']['no_auth'] = FALSE;
$config['mongo_db']['default']['hostname'] = 'localhost';
$config['mongo_db']['default']['port'] = '27017';
$config['mongo_db']['default']['username'] = 'admin';
$config['mongo_db']['default']['password'] = '123456';
$config['mongo_db']['default']['database'] = 'mydatabase';
$config['mongo_db']['default']['db_debug'] = TRUE;
$config['mongo_db']['default']['return_as'] = 'array';
$config['mongo_db']['default']['write_concerns'] = (int)1;
$config['mongo_db']['default']['journal'] = TRUE;
$config['mongo_db']['default']['read_preference'] = NULL;
$config['mongo_db']['default']['read_preference_tags'] = NULL;
$config['mongo_db']['default']['no_auth'] = FALSE;
和application/libraries
中添加了这个库
GIT中心
和autoload.php
$autoload['libraries'] = array('Mongo_db');
和插入、更新、删除示例
检查这个