/** * @param string $identity * @return void */ public function delete(string $identity) { if ($this->collection->count([$this->identityField => $identity]) == 0) { return; } $this->collection->deleteOne([$this->identityField => $identity]); }
/** * @param string $sagaType * @param string $identity * @param array $associationValues * @param string $data * @return void */ public function update(string $sagaType, string $identity, array $associationValues, string $data) { if ($this->collection->count(['identity' => $identity]) == 0) { $this->insert($sagaType, $identity, $associationValues, $data); } else { $this->collection->findOneAndUpdate(['identity' => $identity, 'type' => $sagaType, 'associations' => $associationValues], ['$set' => ['serialized' => $data]]); } }
/** * {@inheritdoc} */ public function count($filter = [], array $options = []) { $event = $this->startQueryLogging(__FUNCTION__, $filter, null, $options); $result = parent::count($filter, $options); $this->logger->logQuery($event); return $result; }
/** * Counts the number of documents in this collection * * @link http://www.php.net/manual/en/mongocollection.count.php * @param array|stdClass $query * @param array $options * @return int Returns the number of documents matching the query. */ public function count($query = [], array $options = []) { try { return $this->collection->count(TypeConverter::fromLegacy($query), $options); } catch (\MongoDB\Driver\Exception\Exception $e) { ExceptionConverter::toLegacy($e); } }
/** * {@inheritdoc} */ public function exists($key) { KeyUtil::validate($key); try { $count = $this->collection->count(array('_id' => $key)); } catch (Exception $e) { throw ReadException::forException($e); } return $count > 0; }
public function readCounts($model, $query, $fields = array(), $sortFields = array(), $limit = 0, $skip = 0) { $options = array('projection' => $fields); if (count($sortFields) > 0) { $options['sort'] = $sortFields; } if ($limit > 0) { $options['limit'] = $limit; } if ($skip > 0) { $options['skip'] = $skip; } $model->totalCount = $this->_collection->count($query); $model->count = $this->_collection->count($query, $options); $model->entries = array(); }
/** * Count queue messages. * * @param array $query in same format as \MongoDB\Collection::find() where top level fields do not contain operators. * Lower level fields can however. eg: valid {a: {$gt: 1}, "b.c": 3}, invalid {$and: [{...}, {...}]} * @param bool|null $running query a running message or not or all * * @return int the count * * @throws \InvalidArgumentException $running was not null and not a bool * @throws \InvalidArgumentException key in $query was not a string */ public function count(array $query, $running = null) { if ($running !== null && !is_bool($running)) { throw new \InvalidArgumentException('$running was not null and not a bool'); } $totalQuery = []; if ($running !== null) { $totalQuery['running'] = $running; } foreach ($query as $key => $value) { if (!is_string($key)) { throw new \InvalidArgumentException('key in $query was not a string'); } $totalQuery["payload.{$key}"] = $value; } return $this->collection->count($totalQuery); }
/** * Counts the number of documents in this collection * * @link http://www.php.net/manual/en/mongocollection.count.php * @param array|stdClass $query * @param array $options * @return int Returns the number of documents matching the query. */ public function count($query = [], $options = []) { try { // Handle legacy mode - limit and skip as second and third parameters, respectively if (!is_array($options)) { $limit = $options; $options = []; if ($limit !== null) { $options['limit'] = (int) $limit; } if (func_num_args() > 2) { $options['skip'] = (int) func_get_args()[2]; } } return $this->collection->count(TypeConverter::fromLegacy($query), $options); } catch (\MongoDB\Driver\Exception\Exception $e) { throw ExceptionConverter::toLegacy($e); } }
/** * @param string $identity * @return bool */ public function contains(string $identity) : bool { return $this->collection->count([$this->identityField => $identity]) > 0; }
/** * Counts the number of documents in this collection * @link http://www.php.net/manual/en/mongocollection.count.php * @param array|stdClass $query * @return int Returns the number of documents matching the query. */ public function count($query = array()) { return $this->collection->count($query); }
/** * Counts the number of results for this cursor. * * @return int The number of documents returned by this cursor's query. */ public function count() : int { return $this->collection->count(...$this->params); }
public function count() { return $this->collection->count(); }
/** * Given an array of tweets and a collection * return the tweets that missing from the collection * * @see self::write() for $options * @param array $tweets * @param \MongoDB\Collection $collection * @param array $options * @return array */ private function filterToSave(array $tweets, \MongoDB\Collection $collection, array $options) { $toSave = []; foreach ($tweets as $key => $tweet) { if (!Parser::match($tweet, $options)) { continue; } $countTweets = $collection->count(['id_str' => $tweet['id_str']]); if ($countTweets === 0) { $toSave[] = $tweet; } } return $toSave; }
/** * * @return int */ public function getCount() { return $this->cacheGet('statistics/count', function () { return $this->collection->count(); }); }
/** * Counts the number of documents in this collection * * @link http://www.php.net/manual/en/mongocollection.count.php * @param array|stdClass $query * @param array $options * @return int Returns the number of documents matching the query. */ public function count($query = [], array $options = []) { return $this->collection->count(TypeConverter::fromLegacy($query), $options); }