/** * @see Collection::count() */ public function count(array $query = [], $limitOrOptions = 0, $skip = 0) { $options = is_array($limitOrOptions) ? array_merge(['limit' => 0, 'skip' => 0], $limitOrOptions) : ['limit' => $limitOrOptions, 'skip' => $skip]; $this->log(['count' => true, 'query' => $query, 'options' => $options, 'limit' => $options['limit'], 'skip' => $options['skip']]); return parent::count($query, $options); }
/** @proxy */ public function count(array $query = array(), $limit = 0, $skip = 0) { $this->log(array('count' => true, 'query' => $query, 'limit' => $limit, 'skip' => $skip)); return parent::count($query, $limit, $skip); }
/** * @param string $identity * @return boolean */ public function contains($identity) { return $this->collection->count([$this->identityField => $identity], 1) > 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']); } }
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: if ($this->query['upsert']) { $this->options['upsert'] = $this->query['upsert']; } 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); case self::TYPE_COUNT: return $this->collection->count($this->query['query']); } }