Skip to content

DOCSP-50301: use client bw in write landing pg #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 23 additions & 41 deletions source/includes/usage-examples/write-code-examples.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
require 'vendor/autoload.php';
require 'vendor/autoload.php';

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

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

// Runs a bulk operation based on the instructions in each array entry
// Runs a bulk operation based on the operations in the ClientBulkWrite object
// start-bulk-write
$result = $collection->bulkWrite(
[
[
'insertOne' => [
['<field name>' => '<value>'],
],
],
[
'replaceOne' => [
['<field to match>' => '<value to match>'],
[
'<first new field>' => '<value>',
'<second new field>' => '<value>',
],
],
],
[
'updateOne' => [
['<field to match>' => '<value to match>'],
['$set' => ['<field to update>' => '<value to update>']],
],
],
[
'updateMany' => [
['<field to match>' => '<value to match>'],
['$set' => ['<field to update>' => '<value to update>']],
],
],
[
'deleteOne' => [
['<field name>' => '<value>'],
],
],
[
'deleteMany' => [
['<field name>' => '<value>'],
],
],
]
$bulkWrite = MongoDB\ClientBulkWrite::createWithCollection($collection);

$bulkWrite->insertOne(['<field name 1>' => '<value 1>', '<field name 2>' => '<value 2>']);

$bulkWrite->updateOne(
['<field to match>' => '<value to match>'],
['$set' => ['<field to update>' => '<updated value>']],
);

$bulkWrite = $bulkWrite->withCollection($anotherCollection);

$bulkWrite->deleteMany(
['<field name>' => '<value>'],
);

$bulkWrite->replaceOne(
['<field to match>' => '<value to match>'],
['<replacement field 1>' => '<replacement value 1>', '<replacement field 2>' => '<replacement value 2>'],
);

$result = $client->bulkWrite($bulkWrite);
// end-bulk-write

// Stores a file in a GridFS bucket and writes data to the file
Expand Down
2 changes: 1 addition & 1 deletion source/write.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ operation:
:language: php
:dedent:

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

Store Large Files
Expand Down
Loading