Skip to content

Commit 0bf30e2

Browse files
committed
DOCSP-50301: use client bw in write landing pg (#259)
* DOCSP-50301: use client bw in write landing pg * NR small fixes (cherry picked from commit a187970)
1 parent c1003b2 commit 0bf30e2

File tree

2 files changed

+24
-42
lines changed

2 files changed

+24
-42
lines changed

source/includes/usage-examples/write-code-examples.php

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2-
require 'vendor/autoload.php';
2+
require 'vendor/autoload.php';
33

44
$uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset');
55
$client = new MongoDB\Client($uri);
66
$collection = $client->db->coll;
7+
$anotherCollection = $client->db->collection;
78

89
// Inserts one document that stores the specified values
910
// start-insert-one
@@ -63,48 +64,29 @@
6364
$result = $collection->deleteMany(['<field name>' => '<value>']);
6465
// end-delete-multiple
6566

66-
// Runs a bulk operation based on the instructions in each array entry
67+
// Runs a bulk operation based on the operations in the ClientBulkWrite object
6768
// start-bulk-write
68-
$result = $collection->bulkWrite(
69-
[
70-
[
71-
'insertOne' => [
72-
['<field name>' => '<value>'],
73-
],
74-
],
75-
[
76-
'replaceOne' => [
77-
['<field to match>' => '<value to match>'],
78-
[
79-
'<first new field>' => '<value>',
80-
'<second new field>' => '<value>',
81-
],
82-
],
83-
],
84-
[
85-
'updateOne' => [
86-
['<field to match>' => '<value to match>'],
87-
['$set' => ['<field to update>' => '<value to update>']],
88-
],
89-
],
90-
[
91-
'updateMany' => [
92-
['<field to match>' => '<value to match>'],
93-
['$set' => ['<field to update>' => '<value to update>']],
94-
],
95-
],
96-
[
97-
'deleteOne' => [
98-
['<field name>' => '<value>'],
99-
],
100-
],
101-
[
102-
'deleteMany' => [
103-
['<field name>' => '<value>'],
104-
],
105-
],
106-
]
69+
$bulkWrite = MongoDB\ClientBulkWrite::createWithCollection($collection);
70+
71+
$bulkWrite->insertOne(['<field name 1>' => '<value 1>', '<field name 2>' => '<value 2>']);
72+
73+
$bulkWrite->updateOne(
74+
['<field to match>' => '<value to match>'],
75+
['$set' => ['<field to update>' => '<updated value>']],
10776
);
77+
78+
$bulkWrite = $bulkWrite->withCollection($anotherCollection);
79+
80+
$bulkWrite->deleteMany(
81+
['<field name>' => '<value>'],
82+
);
83+
84+
$bulkWrite->replaceOne(
85+
['<field to match>' => '<value to match>'],
86+
['<replacement field 1>' => '<replacement value 1>', '<replacement field 2>' => '<replacement value 2>'],
87+
);
88+
89+
$result = $client->bulkWrite($bulkWrite);
10890
// end-bulk-write
10991

11092
// Stores a file in a GridFS bucket and writes data to the file

source/write.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ operation:
171171
:language: php
172172
:dedent:
173173

174-
To learn more about the ``MongoDB\Collection::bulkWrite()`` method, see the
174+
To learn more about the ``MongoDB\Client::bulkWrite()`` method, see the
175175
:ref:`Bulk Write <php-bulk-write>` guide.
176176

177177
Store Large Files

0 commit comments

Comments
 (0)