Skip to content

Commit dea346e

Browse files
authored
PHPLIB-1055: Various small documentation fixes (#1024)
* Use literals instead of RC/RP/WC constants for conciseness * PHPLIB-1057: Note that geoHaystack was removed in MongoDB 5.0+ * Use correct boolean type in updateMany() example code * Better clarify Database::command() purpose and examples Also fixes two long-standing syntax errors in the example code * Revise command tutorial and sync with command() docs Remove the geoNear example since the command itself was removed in MongoDB 4.2.
1 parent 75b99dc commit dea346e

13 files changed

+103
-277
lines changed

docs/reference/method/MongoDBClient-selectCollection.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ with a custom read preference:
7272
'test',
7373
'users',
7474
[
75-
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
75+
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
7676
]
7777
);
7878

docs/reference/method/MongoDBClient-selectDatabase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ preference:
7171
$db = $client->selectDatabase(
7272
'test',
7373
[
74-
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
74+
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
7575
]
7676
);
7777

docs/reference/method/MongoDBCollection-getReadConcern.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Example
3636
<?php
3737

3838
$collection = (new MongoDB\Client)->selectCollection('test', 'users', [
39-
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
39+
'readConcern' => new MongoDB\Driver\ReadConcern('majority'),
4040
]);
4141

4242
var_dump($collection->getReadConcern());

docs/reference/method/MongoDBCollection-updateMany.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The following example updates all of the documents with the ``borough`` of
6161

6262
$updateResult = $collection->updateMany(
6363
[ 'borough' => 'Queens' ],
64-
[ '$set' => [ 'active' => 'True' ]]
64+
[ '$set' => [ 'active' => true ]]
6565
);
6666

6767
printf("Matched %d document(s)\n", $updateResult->getMatchedCount());

docs/reference/method/MongoDBCollection-withOptions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ preference:
5252
$collection = (new MongoDB\Client)->selectCollection('test', 'restaurants');
5353

5454
$newCollection = $sourceCollection->withOptions([
55-
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
55+
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
5656
]);
5757

5858
See Also

docs/reference/method/MongoDBDatabase-command.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Definition
1515

1616
.. phpmethod:: MongoDB\\Database::command()
1717

18-
Execute a :manual:`command </reference/command>` on the database.
18+
Execute a :manual:`command </reference/command>` on the database. This is
19+
generally used to execute commands that do not have a corresponding helper
20+
method within the library.
1921

2022
.. code-block:: php
2123

@@ -43,9 +45,10 @@ Errors/Exceptions
4345
Example
4446
-------
4547

46-
The following example executes a :manual:`ping
47-
</reference/command/ping>` command, which returns a cursor with a single
48-
result document:
48+
Most database commands return a single result document, which can be obtained by
49+
converting the returned cursor to an array and accessing its first element. The
50+
following example executes a :manual:`ping </reference/command/ping>` command
51+
and prints its result document:
4952

5053
.. code-block:: php
5154

@@ -55,7 +58,7 @@ result document:
5558

5659
$cursor = $database->command(['ping' => 1]);
5760

58-
var_dump($c->toArray()[0]);
61+
var_dump($cursor->toArray()[0]);
5962

6063
The output would resemble:
6164

@@ -69,9 +72,11 @@ The output would resemble:
6972
}
7073
}
7174

72-
The following example executes a :manual:`listCollections
73-
</reference/command/listCollections>` command, which returns a cursor with
74-
multiple result documents:
75+
Some database commands return a cursor with multiple results. The following
76+
example executes :manual:`listCollections </reference/command/listCollections>`,
77+
which returns a cursor containing a result document for each collection in the
78+
``test`` database. Note that this example is illustrative; applications would
79+
generally use :phpmethod:`MongoDB\\Database::listCollections()` in practice.
7580

7681
.. code-block:: php
7782

@@ -81,7 +86,7 @@ multiple result documents:
8186

8287
$cursor = $database->command(['listCollections' => 1]);
8388

84-
var_dump($c->toArray());
89+
var_dump($cursor->toArray());
8590

8691
The output would resemble:
8792

docs/reference/method/MongoDBDatabase-getReadConcern.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Example
3636
<?php
3737

3838
$database = (new MongoDB\Client)->selectDatabase('test', [
39-
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
39+
'readConcern' => new MongoDB\Driver\ReadConcern('majority'),
4040
]);
4141

4242
var_dump($database->getReadConcern());

docs/reference/method/MongoDBDatabase-selectCollection.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ database with a custom read preference:
7171
$users = $db->selectCollection(
7272
'users',
7373
[
74-
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
74+
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
7575
]
7676
);
7777

docs/reference/method/MongoDBDatabase-selectGridFSBucket.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ database with a custom read preference:
7171

7272
$imagesBucket = $db->selectGridFSBucket([
7373
'bucketName' => 'images',
74-
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
74+
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
7575
]);
7676

7777
See Also

docs/reference/method/MongoDBDatabase-withOptions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ preference:
5252
$db = (new MongoDB\Client)->test;
5353

5454
$newDb = $db->withOptions([
55-
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
55+
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
5656
]);
5757

5858
See Also

docs/reference/method/MongoDBGridFSBucket-getReadConcern.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Example
3737

3838
$database = (new MongoDB\Client)->selectDatabase('test');
3939
$bucket = $database->selectGridFSBucket([
40-
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
40+
'readConcern' => new MongoDB\Driver\ReadConcern('majority'),
4141
]);
4242

4343
var_dump($bucket->getReadConcern());

docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ Definition
1717

1818
.. phpmethod:: MongoDB\\Model\\IndexInfo::isGeoHaystack()
1919

20-
Return whether the index is a :manual:`geoHaystack
21-
</core/geohaystack>` index.
20+
Return whether the index is a :manual:`geoHaystack </core/geohaystack>`
21+
index.
2222

2323
.. code-block:: php
2424

2525
function isGeoHaystack(): boolean
2626

27+
.. note::
28+
29+
MongoDB 5.0 and later no longer supports geoHaystack indexes.
30+
2731
Return Values
2832
-------------
2933

0 commit comments

Comments
 (0)