Documentation

CountDocuments
in package

FinalYes

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.md#countdocuments

Table of Contents

Properties

$aggregate  : Aggregate
$aggregateOptions  : array<string|int, mixed>
$collectionName  : string
$countOptions  : array<string|int, mixed>
$databaseName  : string
$filter  : array<string|int, mixed>|object

Methods

__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.

  • comment (mixed): BSON value to attach as a comment to this command.

    Only string values are supported for server versions < 4.4.

  • 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

execute()

Execute the operation.

public execute(Server $server) : int
Parameters
$server : Server
Tags
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

        
On this page

Search results