DominionEnterprises\Mongo\Queue::count PHP Method

count() public method

Count queue messages.
public count ( array $query, boolean | null $running = null ) : integer
$query array 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: [{...}, {...}]}
$running boolean | null query a running message or not or all
return integer the count
    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);
    }