File tree Expand file tree Collapse file tree 3 files changed +7
-5
lines changed
includes/fundamentals/read-operations Expand file tree Collapse file tree 3 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -634,7 +634,7 @@ The ``readPreference()`` method accepts the following parameters:
634
634
in the MongoDB PHP extension documentation.
635
635
636
636
The following example queries for documents in which the value of the ``title``
637
- field is ``"Carrie"`` and sets the read preference to ``"secondaryPreferred" ``.
637
+ field is ``"Carrie"`` and sets the read preference to ``ReadPreference::SECONDARY_PREFERRED ``.
638
638
As a result, the query retrieves the results from secondary replica set
639
639
members or the primary member if no secondaries are available:
640
640
@@ -668,7 +668,7 @@ members or the primary member if no secondaries are available:
668
668
public function show()
669
669
{
670
670
$movies = Movie::where('title', 'Carrie')
671
- ->readPreference('secondaryPreferred' )
671
+ ->readPreference(ReadPreference::SECONDARY_PREFERRED )
672
672
->get();
673
673
674
674
return view('browse_movies', [
Original file line number Diff line number Diff line change 7
7
use App \Models \Movie ;
8
8
use Illuminate \Support \Facades \DB ;
9
9
use MongoDB \Laravel \Tests \TestCase ;
10
+ use MongoDB \Driver \ReadPreference ;
10
11
11
12
class ReadOperationsTest extends TestCase
12
13
{
@@ -175,7 +176,7 @@ public function testReadPreference(): void
175
176
{
176
177
// start-read-pref
177
178
$ movies = Movie::where ('title ' , 'Carrie ' )
178
- ->readPreference (' secondaryPreferred ' )
179
+ ->readPreference (ReadPreference:: SECONDARY_PREFERRED )
179
180
->get ();
180
181
// end-read-pref
181
182
Original file line number Diff line number Diff line change @@ -1044,8 +1044,9 @@ set members by setting a read preference.
1044
1044
1045
1045
The following example queries the ``movies`` collection for documents
1046
1046
in which the ``runtime`` value is greater than ``240``. The example passes a
1047
- value of ``"secondary"`` to the ``readPreference()`` method, which sends
1048
- the query to secondary replica set members:
1047
+ value of ``ReadPreference::SECONDARY_PREFERRED`` to the ``readPreference()``
1048
+ method, which sends the query to secondary replica set members
1049
+ or the primary member if no secondaries are available:
1049
1050
1050
1051
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
1051
1052
:language: php
You can’t perform that action at this time.
0 commit comments