php8.5
Home/ Manual/ driver / bulkwrite/ MongoDB\Driver\BulkWrite::count

MongoDB\Driver\BulkWrite::count

PHP function Edit on GitHub ✎

(mongodb >=1.0.0)

Count number of write operations in the bulk

Description

MongoDB\Driver\BulkWrite::count(): int

Returns the number of write operations added to the MongoDB\Driver\BulkWrite object.

Parameters Parameters

Return Values

Returns number of write operations added to the MongoDB\Driver\BulkWrite object.

Errors/Exceptions

Changelog

VersionDescription
PECL mongodb 1.2.0Returns the number of write operations added to the MongoDB\Driver\BulkWrite object. Earlier versions returned the expected number of client-to-server roundtrips required to execute all write operations.

Examples

MongoDB\Driver\BulkWrite::count() example

php
<?php

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['_id' => 1, 'x' => 1]);
$bulk->insert(['_id' => 2, 'x' => 2]);
$bulk->update(['x' => 2], ['$set' => ['x' => 1]]);
$bulk->delete(['x' => 1]);

var_dump(count($bulk));

?>

The above example will output:

output
int(4)

Source: reference/mongodb/mongodb/driver/bulkwrite/count.xml · from the official PHP manual (php/doc-en)