public function execute()
 {
     switch ($this->query['type']) {
         case self::TYPE_FIND:
             if (isset($this->query['mapReduce']['reduce'])) {
                 $this->query['query'][$this->cmd . 'where'] = $this->query['mapReduce']['reduce'];
             }
             $cursor = $this->collection->find($this->query['query'], $this->query['select']);
             $this->prepareCursor($cursor);
             return $cursor;
         case self::TYPE_FIND_AND_UPDATE:
             if ($this->query['sort']) {
                 $this->options['sort'] = $this->query['sort'];
             }
             if ($this->query['select']) {
                 $this->options['fields'] = $this->query['select'];
             }
             if ($this->query['upsert']) {
                 $this->options['upsert'] = true;
             }
             if ($this->query['new']) {
                 $this->options['new'] = true;
             }
             return $this->collection->findAndUpdate($this->query['query'], $this->query['newObj'], $this->options);
         case self::TYPE_FIND_AND_REMOVE:
             if ($this->query['sort']) {
                 $this->options['sort'] = $this->query['sort'];
             }
             if ($this->query['select']) {
                 $this->options['fields'] = $this->query['select'];
             }
             return $this->collection->findAndRemove($this->query['query'], $this->options);
         case self::TYPE_INSERT:
             return $this->collection->insert($this->query['newObj']);
         case self::TYPE_UPDATE:
             return $this->collection->update($this->query['query'], $this->query['newObj'], $this->options);
         case self::TYPE_REMOVE:
             return $this->collection->remove($this->query['query'], $this->options);
         case self::TYPE_GROUP:
             return $this->collection->group($this->query['group']['keys'], $this->query['group']['initial'], $this->query['mapReduce']['reduce'], $this->query['query']);
         case self::TYPE_MAP_REDUCE:
             if (!isset($this->query['mapReduce']['out'])) {
                 $this->query['mapReduce']['out'] = array('inline' => true);
             }
             $cursor = $this->collection->mapReduce($this->query['mapReduce']['map'], $this->query['mapReduce']['reduce'], $this->query['mapReduce']['out'], $this->query['query'], $this->options);
             if ($cursor instanceof Cursor) {
                 $this->prepareCursor($cursor);
             }
             return $cursor;
         case self::TYPE_DISTINCT_FIELD:
             return $this->collection->distinct($this->query['distinctField'], $this->query['query'], $this->options);
         case self::TYPE_GEO_LOCATION:
             if (isset($this->query['limit']) && $this->query['limit']) {
                 $this->options['num'] = $this->query['limit'];
             }
             return $this->collection->near($this->query['near'], $this->query['query'], $this->options);
     }
 }
 /**
  * @see Collection::near()
  */
 public function near($near, array $query = [], array $options = [])
 {
     $this->log(['geoNear' => true, 'near' => $near, 'query' => $query, 'options' => $options]);
     return parent::near($near, $query, $options);
 }
Beispiel #3
0
 public function execute()
 {
     switch ($this->query['type']) {
         case self::TYPE_FIND:
             $cursor = $this->collection->find($this->query['query'], $this->query['select']);
             return $this->prepareCursor($cursor);
         case self::TYPE_FIND_AND_UPDATE:
             if ($this->query['sort']) {
                 $this->options['sort'] = $this->query['sort'];
             }
             if ($this->query['select']) {
                 $this->options['fields'] = $this->query['select'];
             }
             if ($this->query['upsert']) {
                 $this->options['upsert'] = true;
             }
             if ($this->query['new']) {
                 $this->options['new'] = true;
             }
             return $this->collection->findAndUpdate($this->query['query'], $this->query['newObj'], $this->options);
         case self::TYPE_FIND_AND_REMOVE:
             if ($this->query['sort']) {
                 $this->options['sort'] = $this->query['sort'];
             }
             if ($this->query['select']) {
                 $this->options['fields'] = $this->query['select'];
             }
             return $this->collection->findAndRemove($this->query['query'], $this->options);
         case self::TYPE_INSERT:
             return $this->collection->insert($this->query['newObj']);
         case self::TYPE_UPDATE:
             if ($this->query['upsert']) {
                 $this->options['upsert'] = $this->query['upsert'];
             }
             if ($this->query['multiple']) {
                 $this->options['multiple'] = $this->query['multiple'];
             }
             return $this->collection->update($this->query['query'], $this->query['newObj'], $this->options);
         case self::TYPE_REMOVE:
             return $this->collection->remove($this->query['query'], $this->options);
         case self::TYPE_GROUP:
             if (!empty($this->query['query'])) {
                 $this->query['group']['options']['condition'] = $this->query['query'];
             }
             $options = array_merge($this->options, $this->query['group']['options']);
             return $this->collection->group($this->query['group']['keys'], $this->query['group']['initial'], $this->query['group']['reduce'], $options);
         case self::TYPE_MAP_REDUCE:
             if (!isset($this->query['mapReduce']['out'])) {
                 $this->query['mapReduce']['out'] = array('inline' => true);
             }
             $options = array_merge($this->options, $this->query['mapReduce']['options']);
             $cursor = $this->collection->mapReduce($this->query['mapReduce']['map'], $this->query['mapReduce']['reduce'], $this->query['mapReduce']['out'], $this->query['query'], $options);
             if ($cursor instanceof Cursor) {
                 $cursor = $this->prepareCursor($cursor);
             }
             return $cursor;
         case self::TYPE_DISTINCT_FIELD:
             return $this->collection->distinct($this->query['distinctField'], $this->query['query'], $this->options);
         case self::TYPE_GEO_LOCATION:
             if (isset($this->query['limit']) && $this->query['limit']) {
                 $this->options['num'] = $this->query['limit'];
             }
             foreach (array('distanceMultiplier', 'maxDistance', 'spherical') as $key) {
                 if (isset($this->query['geoNear'][$key]) && $this->query['geoNear'][$key]) {
                     $this->options[$key] = $this->query['geoNear'][$key];
                 }
             }
             return $this->collection->near($this->query['geoNear']['near'], $this->query['query'], $this->options);
         case self::TYPE_COUNT:
             return $this->collection->count($this->query['query']);
     }
 }
 /**
  * @see Collection::near()
  */
 public function near($near, array $query = array(), array $options = array())
 {
     $this->log(array('geoNear' => true, 'near' => $near, 'query' => $query, 'options' => $options));
     return parent::near($near, $query, $options);
 }