/**
  * query method
  *  If call getMongoDb() from model, this method call getMongoDb().
  *
  * @param mixed $query
  * @param array $params array()
  * @return void
  * @access public
  */
 public function query()
 {
     $args = func_get_args();
     $query = $args[0];
     $params = array();
     if (count($args) > 1) {
         $params = $args[1];
     }
     if (!$this->isConnected()) {
         return false;
     }
     if ($query === 'getMongoDb') {
         return $this->getMongoDb();
     }
     if (count($args) > 1 && (strpos($args[0], 'findBy') === 0 || strpos($args[0], 'findAllBy') === 0)) {
         $params = $args[1];
         if (substr($args[0], 0, 6) === 'findBy') {
             $field = Inflector::underscore(substr($args[0], 6));
             return $args[2]->find('first', array('conditions' => array($field => $args[1][0])));
         } else {
             $field = Inflector::underscore(substr($args[0], 9));
             return $args[2]->find('all', array('conditions' => array($field => $args[1][0])));
         }
     }
     if (isset($args[2]) && is_a($args[2], 'Model')) {
         $this->_prepareLogQuery($args[2]);
     }
     $return = $this->_db->command($query);
     if ($this->fullDebug) {
         $this->logQuery("db.runCommand( :query )", compact('query'));
     }
     return $return;
 }
Exemple #2
0
 /**
  * Command.
  * 
  * Runs a MongoDB command (such as GeoNear). See the MongoDB documentation for more usage scenarios - http://dochub.mongodb.org/core/commands
  *
  * <code>
  * $this->mongo_db->command(array('geoNear'=>'buildings', 'near'=>array(53.228482, -0.547847), 'num' => 10, 'nearSphere'=>true));
  * </code>
  *
  * @param array $query The command query
  *
  * @access public
  * @return object
  */
 public function command($query = array())
 {
     try {
         $execute = $this->_dbhandle->command($query);
         return $execute;
     } catch (MongoCursorException $exception) {
         $this->_show_error('MongoDB command failed to execute: ' . $exception->getMessage(), 500);
     }
 }
Exemple #3
0
 /**
  * Command.
  *
  * Runs a MongoDB command (such as GeoNear). See the MongoDB documentation
  *  for more usage scenarios - http://dochub.mongodb.org/core/commands
  *
  * @param array $query The command query
  *
  * @access public
  * @return object
  */
 public function command($query = array())
 {
     try {
         $execute = $this->_dbhandle->command($query);
         return $execute;
     } catch (MongoCursorException $Exception) {
         throw new \MongoQB\Exception('MongoDB command failed to execute: ' . $Exception->getMessage());
         // @codeCoverageIgnoreEnd
     }
 }
 /**
  * query method
  *
  * @param mixed $query
  * @param array $params array()
  * @return void
  * @access public
  */
 public function query($query, $params = array())
 {
     $this->_prepareLogQuery($Model);
     // just sets a timer
     $result = $this->_db->command($query);
     if ($this->fullDebug) {
         $this->logQuery("db.runCommand( :query )", compact('query'));
     }
     if ($result['ok']) {
         return $result['values'];
     }
     return $result;
 }
 /**
  * query method
  *  If call getMongoDb() from model, this method call getMongoDb().
  *
  * @param mixed $query
  * @param array $params array()
  * @return void
  * @access public
  */
 public function query($query, $params = array())
 {
     if (!$this->isConnected()) {
         return false;
     }
     if ($query === 'getMongoDb') {
         return $this->getMongoDb();
     }
     $this->_prepareLogQuery($Model);
     // just sets a timer
     $return = $this->_db->command($query);
     if ($this->fullDebug) {
         $this->logQuery("db.runCommand( :query )", compact('query'));
     }
     return $return;
 }