BulkWrite
in package
Operation for executing multiple write operations.
Tags
Table of Contents
Constants
- DELETE_MANY = 'deleteMany'
- DELETE_ONE = 'deleteOne'
- INSERT_ONE = 'insertOne'
- REPLACE_ONE = 'replaceOne'
- UPDATE_MANY = 'updateMany'
- UPDATE_ONE = 'updateOne'
Properties
- $collectionName : string
- $databaseName : string
- $operations : array<string|int, mixed>
- $options : array<string|int, mixed>
Methods
- __construct() : mixed
- Constructs a bulk write operation.
- execute() : BulkWriteResult
- Execute the operation.
- createBulkWriteOptions() : array<string|int, mixed>
- Create options for constructing the bulk write.
- createExecuteOptions() : array<string|int, mixed>
- Create options for executing the bulk write.
- validateOperations() : array<string|int, mixed>
Constants
DELETE_MANY
public
mixed
DELETE_MANY
= 'deleteMany'
DELETE_ONE
public
mixed
DELETE_ONE
= 'deleteOne'
INSERT_ONE
public
mixed
INSERT_ONE
= 'insertOne'
REPLACE_ONE
public
mixed
REPLACE_ONE
= 'replaceOne'
UPDATE_MANY
public
mixed
UPDATE_MANY
= 'updateMany'
UPDATE_ONE
public
mixed
UPDATE_ONE
= 'updateOne'
Properties
$collectionName
private
string
$collectionName
$databaseName
private
string
$databaseName
$operations
private
array<string|int, mixed>
$operations
Tags
$options
private
array<string|int, mixed>
$options
Methods
__construct()
Constructs a bulk write operation.
public
__construct(string $databaseName, string $collectionName, array<string|int, mixed> $operations[, array<string|int, mixed> $options = [] ]) : mixed
Example array structure for all supported operation types:
[ [ 'deleteMany' => [ $filter, $options ] ], [ 'deleteOne' => [ $filter, $options ] ], [ 'insertOne' => [ $document ] ], [ 'replaceOne' => [ $filter, $replacement, $options ] ], [ 'updateMany' => [ $filter, $update, $options ] ], [ 'updateOne' => [ $filter, $update, $options ] ], ]
Arguments correspond to the respective Operation classes; however, the writeConcern option is specified for the top-level bulk write operation instead of each individual operation.
Supported options for deleteMany and deleteOne operations:
- collation (document): Collation specification.
Supported options for replaceOne, updateMany, and updateOne operations:
-
collation (document): Collation specification.
-
upsert (boolean): When true, a new document is created if no document matches the query. The default is false.
Supported options for replaceOne and updateOne operations:
-
sort (document): Determines which document the operation modifies if the query selects multiple documents.
This is not supported for server versions < 8.0 and will result in an exception at execution time if used.
Supported options for updateMany and updateOne operations:
- arrayFilters (document array): A set of filters specifying to which array elements an update should apply.
Supported options for the bulk write operation:
-
builderEncoder (MongoDB\Codec\Encoder): Encoder for query and aggregation builders. If not given, the default encoder will be used.
-
bypassDocumentValidation (boolean): If true, allows the write to circumvent document level validation. The default is false.
-
codec (MongoDB\Codec\DocumentCodec): Codec used to decode documents from BSON to PHP objects. This option is also used to encode PHP objects into BSON for insertOne and replaceOne operations.
-
comment (mixed): BSON value to attach as a comment to this command(s) associated with this bulk write.
This is not supported for servers versions < 4.4.
-
ordered (boolean): If true, when an insert fails, return without performing the remaining writes. If false, when a write fails, continue with the remaining writes, if any. The default is true.
-
let (document): Map of parameter names and values. Values must be constant or closed expressions that do not reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var").
-
session (MongoDB\Driver\Session): Client session.
-
writeConcern (MongoDB\Driver\WriteConcern): Write concern.
Parameters
- $databaseName : string
-
Database name
- $collectionName : string
-
Collection name
- $operations : array<string|int, mixed>
-
List of write operations
- $options : array<string|int, mixed> = []
-
Command options
Tags
execute()
Execute the operation.
public
execute(Server $server) : BulkWriteResult
Parameters
- $server : Server
Tags
Return values
BulkWriteResultcreateBulkWriteOptions()
Create options for constructing the bulk write.
private
createBulkWriteOptions() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>createExecuteOptions()
Create options for executing the bulk write.
private
createExecuteOptions() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>validateOperations()
private
validateOperations(array<string|int, mixed> $operations, DocumentCodec|null $codec, Encoder $builderEncoder) : array<string|int, mixed>
Parameters
- $operations : array<string|int, mixed>
- $codec : DocumentCodec|null
- $builderEncoder : Encoder