CIMongo
MongoDB Library for Codeigniter
By intekhab rizvi
Download the repo and unzip it. You will see 2 folder config and libraries. Paste those 2 folder in your codeigniter application folder.
After this, you will see mongo_db.php file in your application/config and application/libraries folder of codeigniter setup.
Now its time to configure cimongo library as per mongodb login details.
1) Open config/mongo_db.php file and set mongodb login details.
2) Open config/autoload.php file and add 'mongo_db' in $autoload['libraries'] array.
Thats it. Installation and Configuration completed. By default library connect to database provided in "default" group.
Now you can access the methods using $this->mongo_db-> in your controller as well as in model.
You can have more then one database in your application and you can use them simultaneously in your app just like Codeigniter Active Data Record.
1) Open application/config/mongo_db.php file and create one more database group inside that file. For example
$config['mongo_db']['newdb']['hostname'] = 'localhost';
$config['mongo_db']['newdb']['port'] = '27017';
$config['mongo_db']['newdb']['username'] = 'username';
$config['mongo_db']['newdb']['password'] = 'password';
$config['mongo_db']['newdb']['database'] = 'database';
$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;
You can change group name from "newdb" to anything else you want. After changing the group name, save the file.
2) Now open your controller or model file, where you need another database connection active and write below code in the constructor of the class.
$this->load->library('mongo_db', array('activate'=>'newdb'),'mongo_db2');
This will make new connection on new mongoDB and make it available to use as $this->mongo_db2-> inside class