Skip to content

Commit fd77a74

Browse files
authored
Merge pull request #189 from rustagir/DOCSP-44644-dbcoll-accessor-aliases
DOCSP-44644: db/coll access methods
2 parents 343f339 + 91b9614 commit fd77a74

File tree

51 files changed

+524
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+524
-123
lines changed

source/data-formats/modeling-bson-data.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ allows control over how BSON is converted to PHP. Additionally,
2121
the :phpclass:`MongoDB\Client`, :phpclass:`MongoDB\Database`, and
2222
:phpclass:`MongoDB\Collection` classes accept a ``typeMap`` option, which can
2323
be used to specify a default type map to apply to any supporting methods and
24-
selected classes (e.g. :phpmethod:`MongoDB\Client::selectDatabase()`).
24+
selected classes (e.g. :phpmethod:`MongoDB\Client::getDatabase()`).
2525

2626
The :phpclass:`MongoDB\Client`, :phpclass:`MongoDB\Database`, and
2727
:phpclass:`MongoDB\Collection` classes use the following type map by

source/databases-collections.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MongoDB organizes data into a hierarchy of the following levels:
4040
Access a Database
4141
-----------------
4242

43-
Access a database by passing the database name to the ``MongoDB\Client::selectDatabase()``
43+
Access a database by passing the database name to the ``MongoDB\Client::getDatabase()``
4444
method.
4545

4646
The following example accesses a database named ``test_database``:
@@ -76,12 +76,12 @@ Access a Collection
7676

7777
Access a collection by using either of the following methods:
7878

79-
- ``MongoDB\Client::selectCollection()``: Pass the database and collection names as
79+
- ``MongoDB\Client::getCollection()``: Pass the database and collection names as
8080
parameters
81-
- ``MongoDB\Database::selectCollection()``: Pass the collection name as a parameter
81+
- ``MongoDB\Database::getCollection()``: Pass the collection name as a parameter
8282

8383
The following example accesses a collection named ``test_collection`` by using the
84-
``MongoDB\Database::selectCollection()`` method:
84+
``MongoDB\Database::getCollection()`` method:
8585

8686
.. literalinclude:: /includes/databases-collections/databases-collections.php
8787
:language: php
@@ -198,10 +198,10 @@ by specifying a read preference, read concern, or write concern.
198198

199199
By default, databases inherit read and write settings from the ``MongoDB\Client``
200200
instance. Collections inherit these settings from the ``MongoDB\Client`` or
201-
``MongoDB\Database`` instance on which the ``selectCollection()`` method is called.
201+
``MongoDB\Database`` instance on which the ``getCollection()`` method is called.
202202
You can change these settings by passing an options array to the
203-
``MongoDB\Client::selectDatabase()``, ``MongoDB\Client::selectCollection()``, or
204-
``MongoDB\Database::selectCollection()`` methods.
203+
``MongoDB\Client::getDatabase()``, ``MongoDB\Client::getCollection()``, or
204+
``MongoDB\Database::getCollection()`` methods.
205205

206206
To learn more about setting a read preference, read concern, and write concern,
207207
see the :ref:`php-read-write-pref` guide.
@@ -212,9 +212,9 @@ API Documentation
212212
To learn more about any of the methods or types discussed in this
213213
guide, see the following API documentation:
214214

215-
- :phpmethod:`MongoDB\Client::selectDatabase()`
216-
- :phpmethod:`MongoDB\Client::selectCollection()`
217-
- :phpmethod:`MongoDB\Database::selectCollection()`
215+
- :phpmethod:`MongoDB\Client::getDatabase()`
216+
- :phpmethod:`MongoDB\Client::getCollection()`
217+
- :phpmethod:`MongoDB\Database::getCollection()`
218218
- :phpmethod:`MongoDB\Database::createCollection()`
219219
- :phpmethod:`MongoDB\Database::listCollections()`
220220
- :phpmethod:`MongoDB\Database::dropCollection()`

source/examples/aws-lambda/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
try {
1010
$client = new Client($uri);
1111
$planets = $client
12-
->selectCollection('sample_guides', 'planets')
12+
->getCollection('sample_guides', 'planets')
1313
->find([], ['sort' => ['orderFromSun' => 1]]);
1414
} catch (Throwable $exception) {
1515
exit($exception->getMessage());

source/examples/codecs/handling-documents/using-codec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use MongoDB\Client;
44

55
$client = new Client();
6-
$collection = $client->selectCollection('test', 'person', [
6+
$collection = $client->getCollection('test', 'person', [
77
'codec' => new PersonCodec(),
88
]);
99

source/examples/encryption/create_data_key.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
/* Prepare the database for this script. Drop the key vault collection and
1818
* ensure it has a unique index for keyAltNames. This would typically be done
1919
* during application deployment. */
20-
$client->selectCollection('encryption', '__keyVault')->drop();
21-
$client->selectCollection('encryption', '__keyVault')->createIndex(['keyAltNames' => 1], [
20+
$client->getCollection('encryption', '__keyVault')->drop();
21+
$client->getCollection('encryption', '__keyVault')->createIndex(['keyAltNames' => 1], [
2222
'unique' => true,
2323
'partialFilterExpression' => ['keyAltNames' => ['$exists' => true]],
2424
]);

source/examples/encryption/csfle-automatic_encryption-local_schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
* Note: without a server-side schema, another client could potentially insert
6464
* unencrypted data into the collection. Therefore, a local schema should always
6565
* be used in conjunction with a server-side schema. */
66-
$encryptedClient->selectDatabase('test')->createCollection('coll', ['validator' => ['$jsonSchema' => $schema]]);
67-
$encryptedCollection = $encryptedClient->selectCollection('test', 'coll');
66+
$encryptedClient->getDatabase('test')->createCollection('coll', ['validator' => ['$jsonSchema' => $schema]]);
67+
$encryptedCollection = $encryptedClient->getCollection('test', 'coll');
6868

6969
/* Using the encrypted client, insert and find a document to demonstrate that
7070
* the encrypted field is automatically encrypted and decrypted. */
@@ -74,7 +74,7 @@
7474

7575
/* Using the client configured without encryption, find the same document and
7676
* observe that the field is not automatically decrypted. */
77-
$unencryptedCollection = $client->selectCollection('test', 'coll');
77+
$unencryptedCollection = $client->getCollection('test', 'coll');
7878

7979
print_r($unencryptedCollection->findOne(['_id' => 1]));
8080

source/examples/encryption/csfle-automatic_encryption-server_side_schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555

5656
/* Create a new collection for this script. Configure a server-side schema by
5757
* explicitly creating the collection with a "validator" option. */
58-
$encryptedClient->selectDatabase('test')->createCollection('coll', ['validator' => ['$jsonSchema' => $schema]]);
59-
$encryptedCollection = $encryptedClient->selectCollection('test', 'coll');
58+
$encryptedClient->getDatabase('test')->createCollection('coll', ['validator' => ['$jsonSchema' => $schema]]);
59+
$encryptedCollection = $encryptedClient->getCollection('test', 'coll');
6060

6161
/* Using the encrypted client, insert and find a document to demonstrate that
6262
* the encrypted field is automatically encrypted and decrypted. */
@@ -66,7 +66,7 @@
6666

6767
/* Using the client configured without encryption, find the same document and
6868
* observe that the field is not automatically decrypted. */
69-
$unencryptedCollection = $client->selectCollection('test', 'coll');
69+
$unencryptedCollection = $client->getCollection('test', 'coll');
7070

7171
print_r($unencryptedCollection->findOne(['_id' => 1]));
7272

source/examples/encryption/csfle-explicit_encryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'keyId' => $keyId,
3737
]);
3838

39-
$collection = $client->selectCollection('test', 'coll');
39+
$collection = $client->getCollection('test', 'coll');
4040
$collection->insertOne(['_id' => 1, 'encryptedField' => $encryptedValue]);
4141

4242
/* Using the client configured without encryption, find the document and observe

source/examples/encryption/csfle-explicit_encryption_automatic_decryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'keyId' => $keyId,
4343
]);
4444

45-
$collection = $client->selectCollection('test', 'coll');
45+
$collection = $client->getCollection('test', 'coll');
4646
$collection->insertOne(['_id' => 1, 'encryptedField' => $encryptedValue]);
4747

4848
/* Using the client configured with encryption (but not automatic encryption),

source/examples/encryption/key_alt_name.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
/* Prepare the database for this script. Drop the key vault collection and
1919
* ensure it has a unique index for keyAltNames. This would typically be done
2020
* during application deployment. */
21-
$client->selectCollection('encryption', '__keyVault')->drop();
22-
$client->selectCollection('encryption', '__keyVault')->createIndex(['keyAltNames' => 1], [
21+
$client->getCollection('encryption', '__keyVault')->drop();
22+
$client->getCollection('encryption', '__keyVault')->createIndex(['keyAltNames' => 1], [
2323
'unique' => true,
2424
'partialFilterExpression' => ['keyAltNames' => ['$exists' => true]],
2525
]);

source/examples/encryption/queryable_encryption-automatic.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
* infer encryptedFields from the client configuration and manage internal
6060
* encryption collections automatically. Alternatively, the "encryptedFields"
6161
* option can also be passed explicitly. */
62-
$encryptedClient->selectDatabase('test')->createCollection('coll');
63-
$encryptedCollection = $encryptedClient->selectCollection('test', 'coll');
62+
$encryptedClient->getDatabase('test')->createCollection('coll');
63+
$encryptedCollection = $encryptedClient->getCollection('test', 'coll');
6464

6565
/* Using the encrypted client, insert a document and find it by querying on the
6666
* encrypted field. Fields will be automatically encrypted and decrypted. */
@@ -74,6 +74,6 @@
7474

7575
/* Using the client configured without encryption, find the same document and
7676
* observe that fields are not automatically decrypted. */
77-
$unencryptedCollection = $client->selectCollection('test', 'coll');
77+
$unencryptedCollection = $client->getCollection('test', 'coll');
7878

7979
print_r($unencryptedCollection->findOne(['_id' => 1]));

source/examples/encryption/queryable_encryption-explicit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
* option to ensure that internal encryption collections are also created. The
6060
* "encryptedFields" option should also be specified when dropping the
6161
* collection to ensure that internal encryption collections are dropped. */
62-
$encryptedClient->selectDatabase('test')->createCollection('coll', ['encryptedFields' => $encryptedFields]);
63-
$encryptedCollection = $encryptedClient->selectCollection('test', 'coll');
62+
$encryptedClient->getDatabase('test')->createCollection('coll', ['encryptedFields' => $encryptedFields]);
63+
$encryptedCollection = $encryptedClient->getCollection('test', 'coll');
6464

6565
// Insert a document with manually encrypted fields
6666
$indexedInsertPayload = $clientEncryption->encrypt('indexedValue', [

source/includes/databases-collections/databases-collections.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Accesses the "test_database" database
1212
// start-access-database
13-
$db = $client->selectDatabase('test_database');
13+
$db = $client->getDatabase('test_database');
1414
// end-access-database
1515

1616
// Invokes the __get() method to access the "test_database" database
@@ -20,7 +20,7 @@
2020

2121
// Accesses the "test_collection" collection
2222
// start-access-collection
23-
$collection = $client->test_database->selectCollection('test_collection');
23+
$collection = $client->test_database->getCollection('test_collection');
2424
// end-access-collection
2525

2626
// Invokes the __get() method to access the "test_collection" collection
@@ -51,7 +51,7 @@
5151
$readConcern = new ReadConcern(ReadConcern::LOCAL);
5252
$writeConcern = new WriteConcern(WriteConcern::MAJORITY);
5353

54-
$db = $client->selectDatabase('test_database', [
54+
$db = $client->getDatabase('test_database', [
5555
'readPreference' => $readPreference,
5656
'readConcern' => $readConcern,
5757
'writeConcern' => $writeConcern,
@@ -64,7 +64,7 @@
6464
$readConcern = new ReadConcern(ReadConcern::AVAILABLE);
6565
$writeConcern = new WriteConcern(WriteConcern::MAJORITY);
6666

67-
$collection = $client->selectCollection('test_database', 'test_collection', [
67+
$collection = $client->getCollection('test_database', 'test_collection', [
6868
'readPreference' => $readPreference,
6969
'readConcern' => $readConcern,
7070
'writeConcern' => $writeConcern,
@@ -85,7 +85,7 @@
8585
],
8686
);
8787

88-
$db = $client->selectDatabase(
88+
$db = $client->getDatabase(
8989
'test_database',
9090
['readPreference' => $readPreference],
9191
);

source/includes/read-write-pref.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
// Sets read and write settings for the "test_database" database
4545
// start-database-settings
46-
$db = $client->selectDatabase('test_database', [
46+
$db = $client->getDatabase('test_database', [
4747
'readPreference' => new ReadPreference(ReadPreference::PRIMARY_PREFERRED),
4848
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE),
4949
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
@@ -52,7 +52,7 @@
5252

5353
// Sets read and write settings for the "test_collection" collection
5454
// start-collection-settings
55-
$collection = $client->selectCollection('test_database', 'test_collection', [
55+
$collection = $client->getCollection('test_database', 'test_collection', [
5656
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
5757
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE),
5858
'writeConcern' => new WriteConcern(0),
@@ -73,7 +73,7 @@
7373
],
7474
);
7575

76-
$db = $client->selectDatabase(
76+
$db = $client->getDatabase(
7777
'test_database',
7878
['readPreference' => $readPreference],
7979
);

source/includes/usage-examples/sample-app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset');
66
$client = new MongoDB\Client($uri);
77

8-
$collection = $client->selectCollection('<database>', '<collection>');
8+
$collection = $client->getCollection('<database>', '<collection>');
99

1010
// Start example code here
1111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
// Stores a file in a GridFS bucket and writes data to the file
111111
// start-gridfs-upload
112-
$bucket = $client->selectDatabase('<database name>')->selectGridFSBucket();
112+
$bucket = $client->getDatabase('<database name>')->selectGridFSBucket();
113113
$stream = $bucket->openUploadStream('<file name>');
114114
fwrite($stream, '<data>');
115115
fclose($stream);

source/includes/write/run-command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$client = new MongoDB\Client($uri);
99

1010
// start-hello
11-
$database = $client->selectDatabase('myDB');
11+
$database = $client->getDatabase('myDB');
1212
$cursor = $database->command(['hello' => 1]);
1313
// end-hello
1414

source/read-write-pref.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ following methods:
6464
settings
6565
- :ref:`MongoDB\Driver\Session::startTransaction() <php-read-write-transaction>`:
6666
Configures transaction-level settings
67-
- :ref:`MongoDB\Client::selectDatabase() <php-read-write-database>`: Configures
67+
- :ref:`MongoDB\Client::getDatabase() <php-read-write-database>`: Configures
6868
database-level settings
69-
- :ref:`MongoDB\Client::selectCollection() <php-read-write-collection>`: Configures
69+
- :ref:`MongoDB\Client::getCollection() <php-read-write-collection>`: Configures
7070
collection-level settings
7171

7272
.. _php-read-write-client:
@@ -161,7 +161,7 @@ Database Configuration
161161

162162
This example shows how to set the read preference, read concern, and
163163
write concern of a database called ``test_database`` by passing an options
164-
array to the ``selectDatabase()`` method. The code configures the following settings:
164+
array to the ``getDatabase()`` method. The code configures the following settings:
165165

166166
- ``PRIMARY_PREFERRED`` read preference: Read operations retrieve data from
167167
the primary replica set member, or secondary members if the primary is unavailable
@@ -184,7 +184,7 @@ Collection Configuration
184184

185185
This example shows how to set the read preference, read concern, and
186186
write concern of a collection called ``test_collection`` by passing an options
187-
array to the ``selectCollection()`` method. The code configures the following settings:
187+
array to the ``getCollection()`` method. The code configures the following settings:
188188

189189
- ``SECONDARY_PREFERRED`` read preference: Read operations retrieve data from
190190
secondary replica set members, or the primary members if no secondaries are available
@@ -281,8 +281,8 @@ guide, see the following library API documentation:
281281

282282
- :phpmethod:`MongoDB\Client::__construct()`
283283
- :phpmethod:`MongoDB\Client::startSession()`
284-
- :phpmethod:`MongoDB\Client::selectDatabase()`
285-
- :phpmethod:`MongoDB\Client::selectCollection()`
284+
- :phpmethod:`MongoDB\Client::getDatabase()`
285+
- :phpmethod:`MongoDB\Client::getCollection()`
286286

287287
To learn more about the ``startTransaction()`` method, see :php:`MongoDB\Driver\Session::startTransaction()
288288
<mongodb-driver-session.starttransaction>` in the extension API documentation.

source/reference/class/MongoDBClient.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
MongoDB\\Client Class
33
=====================
44

5-
65
.. contents:: On this page
76
:local:
87
:backlinks: none
@@ -32,6 +31,8 @@ Methods
3231
addSubscriber() </reference/method/MongoDBClient-addSubscriber>
3332
createClientEncryption() </reference/method/MongoDBClient-createClientEncryption>
3433
dropDatabase() </reference/method/MongoDBClient-dropDatabase>
34+
getCollection() </reference/method/MongoDBClient-getCollection>
35+
getDatabase() </reference/method/MongoDBClient-getDatabase>
3536
getManager() </reference/method/MongoDBClient-getManager>
3637
getReadConcern() </reference/method/MongoDBClient-getReadConcern>
3738
getReadPreference() </reference/method/MongoDBClient-getReadPreference>
@@ -50,6 +51,8 @@ Methods
5051
- :phpmethod:`MongoDB\Client::addSubscriber()`
5152
- :phpmethod:`MongoDB\Client::createClientEncryption()`
5253
- :phpmethod:`MongoDB\Client::dropDatabase()`
54+
- :phpmethod:`MongoDB\Client::getCollection()`
55+
- :phpmethod:`MongoDB\Client::getDatabase()`
5356
- :phpmethod:`MongoDB\Client::getManager()`
5457
- :phpmethod:`MongoDB\Client::getReadConcern()`
5558
- :phpmethod:`MongoDB\Client::getReadPreference()`

source/reference/class/MongoDBCollection.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Definition
2121
:php:`MongoDB\Driver\Manager <class.mongodb-driver-manager>` class or
2222
select a collection from the library's :phpclass:`MongoDB\Client` or
2323
:phpclass:`MongoDB\Database` classes. A collection may also be cloned from
24-
an existing :phpclass:`MongoDB\Collection` object via the
24+
an existing :phpclass:`MongoDB\Collection` object by using the
2525
:phpmethod:`withOptions() <MongoDB\Collection::withOptions()>` method.
2626

2727
:phpclass:`MongoDB\Collection` supports the :php:`readConcern

source/reference/class/MongoDBDatabase.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Definition
2121
:php:`MongoDB\Driver\Manager <class.mongodb-driver-manager>` class or
2222
select a database from the library's :phpclass:`MongoDB\Client` class. A
2323
database may also be cloned from an existing :phpclass:`MongoDB\Database`
24-
object via the :phpmethod:`withOptions() <MongoDB\Database::withOptions()>`
24+
object by using the :phpmethod:`withOptions() <MongoDB\Database::withOptions()>`
2525
method.
2626

2727
:phpclass:`MongoDB\Database` supports the :php:`readConcern
@@ -50,6 +50,7 @@ Methods
5050
createEncryptedCollection() </reference/method/MongoDBDatabase-createEncryptedCollection>
5151
drop() </reference/method/MongoDBDatabase-drop>
5252
dropCollection() </reference/method/MongoDBDatabase-dropCollection>
53+
getCollection() </reference/method/MongoDBDatabase-getCollection>
5354
getDatabaseName() </reference/method/MongoDBDatabase-getDatabaseName>
5455
getManager() </reference/method/MongoDBDatabase-getManager>
5556
getReadConcern() </reference/method/MongoDBDatabase-getReadConcern>
@@ -73,6 +74,7 @@ Methods
7374
- :phpmethod:`MongoDB\Database::createEncryptedCollection()`
7475
- :phpmethod:`MongoDB\Database::drop()`
7576
- :phpmethod:`MongoDB\Database::dropCollection()`
77+
- :phpmethod:`MongoDB\Database::getCollection()`
7678
- :phpmethod:`MongoDB\Database::getDatabaseName()`
7779
- :phpmethod:`MongoDB\Database::getManager()`
7880
- :phpmethod:`MongoDB\Database::getReadConcern()`

0 commit comments

Comments
 (0)