<commit_before><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * CodeIgniter MongoDB Active Record Library
 *
 * A library to interface with the NoSQL database MongoDB. For more information see http://www.mongodb.org
 * Originally created by <NAME>, but extended and updated by <NAME>
 *
 * @package		CodeIgniter
 * @author		<NAME> | www.alexbilbie.com | <EMAIL>
 * @author		<NAME> | www.kyledye.com | <EMAIL>
 * @author		<NAME> | www.10layer.com | <EMAIL>
 * @copyright	Copyright (c) 2010, <NAME>.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://alexbilbie.com
 * @link		http://kyledye.com
 * @version		Version 0.3.2
 */

class Mongo_db {
	
	private $CI;
	private $config_file = 'mongodb';
	
	private $connection;
	private $db;
	private $connection_string;
	
	private $host;
	private $port;
	private $user;
	private $pass;
	private $dbname;
	private $persist;
	private $persist_key;
	
	private $selects = array('_id'=>0);
	public $wheres = array();
	private $sorts = array();
	
	private $cache=false;
	
	private $limit = 999999;
	private $offset = 0;
	
	public $error=false;
	public $errormsg="";
	
	/**
	*	--------------------------------------------------------------------------------
	*	CONSTRUCTOR
	*	--------------------------------------------------------------------------------
	*
	*	Automatically check if the Mongo PECL extension has been installed/enabled.
	*	Generate the connection string and establish a connection to the MongoDB.
	*/
	
	public function __construct() {
		if(!class_exists('Mongo')):
			show_error("The MongoDB PECL extension has not been installed or enabled", 500);
		endif;
		$this->CI =& get_instance();
		$this->connection_string();
		$this->connect();
	}
	
	/**
	*	--------------------------------------------------------------------------------
	*	Switch_db
	*	--------------------------------------------------------------------------------
	*
	*	Switch from default database to a different db
	*/
	
	public function switch_db($database = '') {
		if(empty($database)):
			show_error("To switch MongoDB databases, a new database name must be specified", 500);
		endif;
		$this->dbname = $database;
		try {
			$this->db = $this->connection->{$this->dbname};
			return(TRUE);
		} catch(Exception $e) {
			show_error("Unable to switch Mongo Databases: {$e->getMessage()}", 500);
		}
	}
		
	/**
	*	--------------------------------------------------------------------------------
	*	Drop_db
	*	--------------------------------------------------------------------------------
	*
	*	Drop a Mongo database
	*	@usage: $this->mongo_db->drop_db("foobar");
	*/
	public function drop_db($database = '')
	{
		if(empty($database))
		{
			show_error('Failed to drop MongoDB database because name is empty', 500);
		}
		
		else
		{
			try {
				$this->connection->{$database}->drop();
				return TRUE;
			} catch (Exception $e) {
				show_error("Unable to drop Mongo database `{$database}`: {$e->getMessage()}", 500);
			}
			
		}
		
		return($this);
	}
		
	/**
	*	--------------------------------------------------------------------------------
	*	Drop_collection
	*	--------------------------------------------------------------------------------
	*
	*	Drop a Mongo collection
	*	@usage: $this->mongo_db->drop_collection('foo', 'bar');
	*/
	public function drop_collection($db = "", $col = "")
	{
		if(empty($db))
		{
			show_error('Failed to drop MongoDB collection because database name is empty', 500);
		}
	
		if(empty($col))
		{
			show_error('Failed to drop MongoDB collection because collection name is empty', 500);
		}
		
		else
		{
			try {
				$this->connection->{$db}->{$col}->drop();
				return TRUE;
			} catch (Exception $e) {
				show_error("Unable to drop Mongo collection `{$col}`: {$e->getMessage()}", 500);
			}
		}
		
		return($this);
	}
	
	/**
	*	--------------------------------------------------------------------------------
	*	SELECT FIELDS
	*	--------------------------------------------------------------------------------
	*
	*	Determine which fields to include OR which to exclude during the query process.
	*	Currently, including and excluding at the same time is not available, so the 
	*	$includes array will take precedence over the $excludes array.  If you want to <commit_msg>Get MongoDB Collections list<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * CodeIgniter MongoDB Active Record Library
 *
 * A library to interface with the NoSQL database MongoDB. For more information see http://www.mongodb.org
 * Originally created by <NAME>, but extended and updated by <NAME>
 *
 * @package		CodeIgniter
 * @author		<NAME> | www.alexbilbie.com | <EMAIL>
 * @author		<NAME> | www.kyledye.com | <EMAIL>
 * @author		<NAME> | www.10layer.com | <EMAIL>
 * @copyright	Copyright (c) 2010, <NAME>.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://alexbilbie.com
 * @link		http://kyledye.com
 * @version		Version 0.3.2
 */

class Mongo_db {
	
	private $CI;
	private $config_file = 'mongodb';
	
	private $connection;
	private $db;
	private $connection_string;
	
	private $host;
	private $port;
	private $user;
	private $pass;
	private $dbname;
	private $persist;
	private $persist_key;
	
	private $selects = array('_id'=>0);
	public $wheres = array();
	private $sorts = array();
	
	private $cache=false;
	
	private $limit = 999999;
	private $offset = 0;
	
	public $error=false;
	public $errormsg="";
	
	/**
	*	--------------------------------------------------------------------------------
	*	CONSTRUCTOR
	*	--------------------------------------------------------------------------------
	*
	*	Automatically check if the Mongo PECL extension has been installed/enabled.
	*	Generate the connection string and establish a connection to the MongoDB.
	*/
	
	public function __construct() {
		if(!class_exists('Mongo')):
			show_error("The MongoDB PECL extension has not been installed or enabled", 500);
		endif;
		$this->CI =& get_instance();
		$this->connection_string();
		$this->connect();
	}
	
	/**
	*	--------------------------------------------------------------------------------
	*	Switch_db
	*	--------------------------------------------------------------------------------
	*
	*	Switch from default database to a different db
	*/
	
	public function switch_db($database = '') {
		if(empty($database)):
			show_error("To switch MongoDB databases, a new database name must be specified", 500);
		endif;
		$this->dbname = $database;
		try {
			$this->db = $this->connection->{$this->dbname};
			return(TRUE);
		} catch(Exception $e) {
			show_error("Unable to switch Mongo Databases: {$e->getMessage()}", 500);
		}
	}
		
	/**
	*	--------------------------------------------------------------------------------
	*	Drop_db
	*	--------------------------------------------------------------------------------
	*
	*	Drop a Mongo database
	*	@usage: $this->mongo_db->drop_db("foobar");
	*/
	public function drop_db($database = '')
	{
		if(empty($database))
		{
			show_error('Failed to drop MongoDB database because name is empty', 500);
		}
		
		else
		{
			try {
				$this->connection->{$database}->drop();
				return TRUE;
			} catch (Exception $e) {
				show_error("Unable to drop Mongo database `{$database}`: {$e->getMessage()}", 500);
			}
			
		}
		
		return($this);
	}
		
	/**
	*	--------------------------------------------------------------------------------
	*	Drop_collection
	*	--------------------------------------------------------------------------------
	*
	*	Drop a Mongo collection
	*	@usage: $this->mongo_db->drop_collection('foo', 'bar');
	*/
	public function drop_collection($db = "", $col = "")
	{
		if(empty($db))
		{
			show_error('Failed to drop MongoDB collection because database name is empty', 500);
		}
	
		if(empty($col))
		{
			show_error('Failed to drop MongoDB collection because collection name is empty', 500);
		}
		
		else
		{
			try {
				$this->connection->{$db}->{$col}->drop();
				return TRUE;
			} catch (Exception $e) {
				show_error("Unable to drop Mongo collection `{$col}`: {$e->getMessage()}", 500);
			}
		}
		
		return($this);
	}
	
	/**
	 * collections function.
	 * 
	 * Returns a list of collections for a specific database
	 *
	 * @access public
	 * @param string $db. (default: "")
	 * @return void
	 */
	public function collections($db = "") {
		return $this->db->listCollections();
	}
	
	/**
	*	--------------------------------------------------------------------------------
	*	SELECT FIELDS
	*	--------------------------------------------------------------------------------
	*
	*	Determine which fields to include OR which to exclude during the query process.
	*	Currently, including and excluding at the same time is not available, so the 
	*	$includes array will take precedence over the $excludes array.  If you want to 
{'fraction_non_alphanumeric': 0.30173579801623085, 'fraction_numerical': 0.009242560865644725, 'mean_word_length': 1.7470588235294118, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '945250', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2462, 'n_words': 683}