public function __construct()
 {
     $config = CL_Config::get_instance();
     // Retrieve MongoDB config
     $host = $config->get_item('database', 'mongo_server');
     $port = $config->get_item('database', 'mongo_port');
     $user = $config->get_item('database', 'mongo_user');
     $password = $config->get_item('database', 'mongo_password');
     $database = $config->get_item('database', 'mongo_database');
     // Build connection URI
     $uri = 'mongodb://';
     $uri .= $user !== NULL ? $user . ':' . $password . '@' : '';
     $uri .= $host !== NULL ? $host : 'localhost';
     $uri .= $port !== NULL ? ':' . $port : '';
     // Connect to MongoDB
     try {
         $this->m = new MongoClient($uri);
     } catch (MongoConnectionException $e) {
         throwErrorAndExit($e->getMessage());
     }
     // Use database
     $this->db = $this->m->{$database};
 }
 /**
  * @AjaxCallable=TRUE
  * @AjaxMethod=POST
  * @AjaxAsync=TRUE
  */
 function get_query()
 {
     $caseId = $this->session->get('caseId');
     $res = $this->db->select('query', 'text', ['caseId' => $caseId]);
     // Handle possible error
     if (!$res) {
         throwErrorAndExit($this->db->getError());
     }
     return ['body' => $this->db->fetchObject()->text, 'isError' => FALSE, 'errCode' => 0];
 }