Documentation

CountDocuments
in package
implements Executable

Operation for obtaining an exact count of documents in a collection

Tags
see
Collection::countDocuments()
see
https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#countdocuments

Interfaces, Classes, Traits and Enums

Executable

Table of Contents

$aggregate  : Aggregate
$aggregateOptions  : array<string|int, mixed>
$collectionName  : string
$countOptions  : array<string|int, mixed>
$databaseName  : string
$filter  : array<string|int, mixed>|object
__construct()  : mixed
Constructs an aggregate command for counting documents
execute()  : int
Execute the operation.
createAggregate()  : Aggregate

Properties

$aggregateOptions

private array<string|int, mixed> $aggregateOptions

Methods

__construct()

Constructs an aggregate command for counting documents

public __construct(string $databaseName, string $collectionName, array<string|int, mixed>|object $filter[, array<string|int, mixed> $options = [] ]) : mixed

Supported options:

  • collation (document): Collation specification.

  • hint (string|document): The index to use. Specify either the index name as a string or the index key pattern as a document. If specified, then the query system will only consider plans using the hinted index.

  • limit (integer): The maximum number of documents to count.

  • maxTimeMS (integer): The maximum amount of time to allow the query to run.

  • readConcern (MongoDB\Driver\ReadConcern): Read concern.

  • readPreference (MongoDB\Driver\ReadPreference): Read preference.

  • session (MongoDB\Driver\Session): Client session.

  • skip (integer): The number of documents to skip before returning the documents.

Parameters
$databaseName : string

Database name

$collectionName : string

Collection name

$filter : array<string|int, mixed>|object

Query by which to filter documents

$options : array<string|int, mixed> = []

Command options

Tags
throws
InvalidArgumentException

for parameter/option parsing errors

Return values
mixed

execute()

Execute the operation.

public execute(Server $server) : int
Parameters
$server : Server
Tags
see
Executable::execute()
throws
UnexpectedValueException

if the command response was malformed

throws
UnsupportedException

if collation or read concern is used and unsupported

throws
RuntimeException

for other driver errors (e.g. connection errors)

Return values
int

Search results