-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41965: Read and write settings #146
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
norareidy
merged 11 commits into
mongodb:php-standardization
from
norareidy:DOCSP-41965-read-write-pref
Sep 25, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3d7ae37
DOCSP-41965: Read and write settings
norareidy 857753b
more info
norareidy 2aab86a
edits
norareidy d0e6934
edits
norareidy 0966a2a
headers
norareidy e31a674
fix link
norareidy 79e3608
fix
norareidy a36917d
RR feedback
norareidy 1bcd46e
api docs
norareidy 2f570f5
fix
norareidy e48c5b4
fix
norareidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
use MongoDB\Driver\ReadConcern; | ||
use MongoDB\Driver\ReadPreference; | ||
use MongoDB\Driver\WriteConcern; | ||
use MongoDB\Client; | ||
|
||
// start-client-settings | ||
$clientOptions = [ | ||
'readPreference' => 'secondary', | ||
'readConcernLevel' => 'local', | ||
'w' => '2', | ||
]; | ||
|
||
$client = new Client('mongodb://localhost:27017', $clientOptions); | ||
// end-client-settings | ||
|
||
// start-client-settings-uri | ||
$uri = 'mongodb://localhost:27017/?readPreference=secondary&readConcernLevel=local&w=2'; | ||
$client = new Client($uri); | ||
// end-client-settings-uri | ||
|
||
// start-session-settings | ||
$sessionOptions = [ | ||
'readPreference' => new ReadPreference(ReadPreference::PRIMARY_PREFERRED), | ||
'readConcern' => new ReadConcern(ReadConcern::LOCAL), | ||
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY), | ||
]; | ||
|
||
$session = $client->startSession($sessionOptions); | ||
// end-session-settings | ||
|
||
// start-transaction-settings | ||
$transactionOptions = [ | ||
'readPreference' => new ReadPreference(ReadPreference::PRIMARY), | ||
'readConcern' => new ReadConcern(ReadConcern::MAJORITY), | ||
'writeConcern' => new WriteConcern(1), | ||
]; | ||
|
||
$session->startTransaction($transactionOptions); | ||
// end-transaction-settings | ||
|
||
// Sets read and write settings for the "test_database" database | ||
// start-database-settings | ||
$db = $client->selectDatabase('test_database', [ | ||
'readPreference' => new ReadPreference(ReadPreference::PRIMARY_PREFERRED), | ||
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE), | ||
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY), | ||
]); | ||
// end-database-settings | ||
|
||
// Sets read and write settings for the "test_collection" collection | ||
// start-collection-settings | ||
$collection = $client->selectCollection('test_database', 'test_collection', [ | ||
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED), | ||
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE), | ||
'writeConcern' => new WriteConcern(0), | ||
]); | ||
|
||
// end-collection-settings | ||
|
||
// Instructs the library to prefer reads from secondary replica set members | ||
// located in New York, followed by a secondary in San Francisco, and | ||
// lastly fall back to any secondary. | ||
// start-tag-set | ||
$readPreference = new ReadPreference( | ||
ReadPreference::RP_SECONDARY, | ||
[ | ||
['dc' => 'ny'], | ||
['dc' => 'sf'], | ||
[], | ||
], | ||
); | ||
|
||
$db = $client->selectDatabase( | ||
'test_database', | ||
['readPreference' => $readPreference], | ||
); | ||
|
||
// end-tag-set | ||
|
||
// Instructs the library to distribute reads between members within 35 milliseconds | ||
// of the closest member's ping time | ||
// start-local-threshold | ||
$options = [ | ||
'replicaSet' => 'repl0', | ||
'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), | ||
'localThresholdMS' => 35, | ||
]; | ||
|
||
$client = new Client('mongodb://localhost:27017', [], $options); | ||
// end-local-threshold |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ MongoDB PHP Library | |
/aggregation | ||
/indexes | ||
/security | ||
/read-write-pref | ||
/tutorial | ||
/upgrade | ||
/reference | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: I think that this section might be better suited to be under the read/write drawers
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether to put it under read or write - I guess read if I had to choose, since there's more content on read settings configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think you need to put it in a drawer but just in the list under read and write