Commit 6385fe0b authored by Jeremy Mikola's avatar Jeremy Mikola

Merge branch 'v1.1'

parents 55e871bf 2d2f443d
...@@ -138,7 +138,7 @@ database, and reads it back as an object of the same type: ...@@ -138,7 +138,7 @@ database, and reads it back as an object of the same type:
<?php <?php
$collection = (new MongoDB\Client)->demo->persons; $collection = (new MongoDB\Client)->test->persons;
$result = $collection->insertOne(new Person('Bob')); $result = $collection->insertOne(new Person('Bob'));
...@@ -219,7 +219,7 @@ everything as a PHP array: ...@@ -219,7 +219,7 @@ everything as a PHP array:
] ]
); );
$document = $client->demo->zips->findOne(['_id' => '94301']); $document = $client->test->zips->findOne(['_id' => '94301']);
var_dump($document); var_dump($document);
......
...@@ -46,7 +46,7 @@ Errors/Exceptions ...@@ -46,7 +46,7 @@ Errors/Exceptions
Example Example
------- -------
The following example drops the ``demo`` database: The following example drops the ``test`` database:
.. code-block:: php .. code-block:: php
...@@ -54,7 +54,7 @@ The following example drops the ``demo`` database: ...@@ -54,7 +54,7 @@ The following example drops the ``demo`` database:
$client = new MongoDB\Client; $client = new MongoDB\Client;
$result = $client->dropDatabase('demo'); $result = $client->dropDatabase('test');
var_dump($result); var_dump($result);
...@@ -64,7 +64,7 @@ The output would then resemble:: ...@@ -64,7 +64,7 @@ The output would then resemble::
["storage":"ArrayObject":private]=> ["storage":"ArrayObject":private]=>
array(2) { array(2) {
["dropped"]=> ["dropped"]=>
string(4) "demo" string(4) "test"
["ok"]=> ["ok"]=>
float(1) float(1)
} }
......
...@@ -49,7 +49,7 @@ overridden via the ``$options`` parameter. ...@@ -49,7 +49,7 @@ overridden via the ``$options`` parameter.
Example Example
------- -------
The following example selects the ``users`` collection in the ``demo`` database: The following example selects the ``users`` collection in the ``test`` database:
.. code-block:: php .. code-block:: php
...@@ -57,9 +57,9 @@ The following example selects the ``users`` collection in the ``demo`` database: ...@@ -57,9 +57,9 @@ The following example selects the ``users`` collection in the ``demo`` database:
$client = new MongoDB\Client; $client = new MongoDB\Client;
$collection = $client->selectCollection('demo', 'users'); $collection = $client->selectCollection('test', 'users');
The following example selects the ``users`` collection in the ``demo`` database The following example selects the ``users`` collection in the ``test`` database
with a custom read preference: with a custom read preference:
.. code-block:: php .. code-block:: php
...@@ -69,7 +69,7 @@ with a custom read preference: ...@@ -69,7 +69,7 @@ with a custom read preference:
$client = new MongoDB\Client; $client = new MongoDB\Client;
$collection = $client->selectCollection( $collection = $client->selectCollection(
'demo', 'test',
'users', 'users',
[ [
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY), 'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
......
...@@ -49,7 +49,7 @@ via the ``$options`` parameter. ...@@ -49,7 +49,7 @@ via the ``$options`` parameter.
Example Example
------- -------
The following example selects the ``demo`` database: The following example selects the ``test`` database:
.. code-block:: php .. code-block:: php
...@@ -57,9 +57,9 @@ The following example selects the ``demo`` database: ...@@ -57,9 +57,9 @@ The following example selects the ``demo`` database:
$client = new MongoDB\Client; $client = new MongoDB\Client;
$db = $client->selectDatabase('demo'); $db = $client->selectDatabase('test');
The following examples selects the ``demo`` database with a custom read The following examples selects the ``test`` database with a custom read
preference: preference:
.. code-block:: php .. code-block:: php
...@@ -69,7 +69,7 @@ preference: ...@@ -69,7 +69,7 @@ preference:
$client = new MongoDB\Client; $client = new MongoDB\Client;
$db = $client->selectDatabase( $db = $client->selectDatabase(
'demo', 'test',
[ [
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY), 'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
] ]
......
...@@ -50,7 +50,7 @@ any options, use the :phpmethod:`MongoDB\\Client::selectDatabase` method. ...@@ -50,7 +50,7 @@ any options, use the :phpmethod:`MongoDB\\Client::selectDatabase` method.
Examples Examples
-------- --------
The following example selects the ``demo`` and ``another-app`` databases: The following example selects the ``test`` and ``another-app`` databases:
.. code-block:: php .. code-block:: php
...@@ -58,7 +58,7 @@ The following example selects the ``demo`` and ``another-app`` databases: ...@@ -58,7 +58,7 @@ The following example selects the ``demo`` and ``another-app`` databases:
$client = new MongoDB\Client; $client = new MongoDB\Client;
$demo = $client->demo; $test = $client->test;
$anotherApp = $client->{'another-app'}; $anotherApp = $client->{'another-app'};
See Also See Also
......
...@@ -54,13 +54,13 @@ Create a Compound Index ...@@ -54,13 +54,13 @@ Create a Compound Index
The following example creates a :manual:`compound index </core/index-compound>` The following example creates a :manual:`compound index </core/index-compound>`
on the ``borough`` and ``cuisine`` fields in the ``restaurants`` collection in on the ``borough`` and ``cuisine`` fields in the ``restaurants`` collection in
the ``example`` database. the ``test`` database.
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->selectCollection('example', 'restaurants'); $collection = (new MongoDB\Client)->selectCollection('test', 'restaurants');
$indexName = $collection->createIndex(['borough' => 1, 'cuisine' => 1]); $indexName = $collection->createIndex(['borough' => 1, 'cuisine' => 1]);
...@@ -74,7 +74,7 @@ Create a Partial Index ...@@ -74,7 +74,7 @@ Create a Partial Index
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
The following example adds a :manual:`partial index </core/index-parital>` on The following example adds a :manual:`partial index </core/index-parital>` on
the ``borough`` field in the ``restaurants`` collection in the ``example`` the ``borough`` field in the ``restaurants`` collection in the ``test``
database. The partial index indexes only documents where the ``borough`` field database. The partial index indexes only documents where the ``borough`` field
exists. exists.
...@@ -82,7 +82,7 @@ exists. ...@@ -82,7 +82,7 @@ exists.
<?php <?php
$collection = (new MongoDB\Client)->selectCollection('example, 'restaurants'); $collection = (new MongoDB\Client)->selectCollection('test, 'restaurants');
$indexName = $collection->createIndex( $indexName = $collection->createIndex(
['borough' => 1], ['borough' => 1],
......
...@@ -64,7 +64,7 @@ Example ...@@ -64,7 +64,7 @@ Example
------- -------
The following example creates two indexes on the ``restaurants`` collection in The following example creates two indexes on the ``restaurants`` collection in
the ``example`` database. One index is a compound index on the ``borough`` and the ``test`` database. One index is a compound index on the ``borough`` and
``cuisine`` fields and the other is 2dsphere index on the ``loc`` field with a ``cuisine`` fields and the other is 2dsphere index on the ``loc`` field with a
custom name. custom name.
...@@ -72,7 +72,7 @@ custom name. ...@@ -72,7 +72,7 @@ custom name.
<?php <?php
$collection = (new MongoDB\Client)->selectCollection('example', 'restaurants'); $collection = (new MongoDB\Client)->selectCollection('test', 'restaurants');
$indexNames = $collection->createIndexes([ $indexNames = $collection->createIndexes([
[ 'key' => [ 'borough' => 1, 'cuisine' => 1] ], [ 'key' => [ 'borough' => 1, 'cuisine' => 1] ],
......
...@@ -59,7 +59,7 @@ that have ``"ny"`` as the value for the ``state`` field: ...@@ -59,7 +59,7 @@ that have ``"ny"`` as the value for the ``state`` field:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
......
...@@ -61,7 +61,7 @@ has ``"ny"`` as the value for the ``state`` field: ...@@ -61,7 +61,7 @@ has ``"ny"`` as the value for the ``state`` field:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
......
...@@ -54,13 +54,13 @@ Return Distinct Values for a Field ...@@ -54,13 +54,13 @@ Return Distinct Values for a Field
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example identifies the distinct values for the ``borough`` field The following example identifies the distinct values for the ``borough`` field
in the ``restaurants`` collection in the ``example`` database. in the ``restaurants`` collection in the ``test`` database.
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$distinct = $collection->distinct('borough'); $distinct = $collection->distinct('borough');
...@@ -87,14 +87,14 @@ Return Distinct Values Using a Filter ...@@ -87,14 +87,14 @@ Return Distinct Values Using a Filter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example identifies the distinct values for the ``cuisine`` field The following example identifies the distinct values for the ``cuisine`` field
in the ``restaurants`` collection in the ``example`` database for documents in the ``restaurants`` collection in the ``test`` database for documents where
where the ``borough`` is ``Queens``: the ``borough`` is ``Queens``:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$distinct = $collection->distinct('cuisine', ['borough' => 'Queens']); $distinct = $collection->distinct('cuisine', ['borough' => 'Queens']);
......
...@@ -46,14 +46,14 @@ Errors/Exceptions ...@@ -46,14 +46,14 @@ Errors/Exceptions
Example Example
------- -------
The following operation drops the ``restaurants`` collection in the ``example`` The following operation drops the ``restaurants`` collection in the ``test``
database: database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$result = $collection->drop(); $result = $collection->drop();
...@@ -65,7 +65,7 @@ The output would then resemble:: ...@@ -65,7 +65,7 @@ The output would then resemble::
["storage":"ArrayObject":private]=> ["storage":"ArrayObject":private]=>
array(3) { array(3) {
["ns"]=> ["ns"]=>
string(19) "example.restaurants" string(16) "test.restaurants"
["nIndexesWas"]=> ["nIndexesWas"]=>
int(3) int(3)
["ok"]=> ["ok"]=>
......
...@@ -47,13 +47,13 @@ Example ...@@ -47,13 +47,13 @@ Example
------- -------
The following drops an indexes with name ``borough_1`` from the ``restaurants`` The following drops an indexes with name ``borough_1`` from the ``restaurants``
collection in the ``example`` database: collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$result = $collection->dropIndex('borough_1'); $result = $collection->dropIndex('borough_1');
......
...@@ -48,13 +48,13 @@ Example ...@@ -48,13 +48,13 @@ Example
------- -------
The following drops all indexes from the ``restaurants`` collection in the The following drops all indexes from the ``restaurants`` collection in the
``example`` database: ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$result = $collection->dropIndexes(); $result = $collection->dropIndexes();
......
...@@ -56,7 +56,7 @@ returned. It also limits the results to 5 documents. ...@@ -56,7 +56,7 @@ returned. It also limits the results to 5 documents.
.. code-block:: php .. code-block:: php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$cursor = $collection->find( $cursor = $collection->find(
[ [
......
...@@ -51,6 +51,28 @@ Behavior ...@@ -51,6 +51,28 @@ Behavior
Examples Examples
-------- --------
Matching BSON Types in Query Criteria
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the following example, documents in the ``restaurants`` collection use an
:manual:`ObjectId </reference/object-id/>` for their identifier (the default)
and documents in the ``zips`` collection use a string. Since ObjectID is a
special BSON type, the query criteria for selecting a restaurant must use the
:php:`MongoDB\\BSON\\ObjectID <class.mongodb-bson-objectid>` class.
.. code-block:: php
$database = (new MongoDB\Client)->test;
$zip = $database->zips->findOne(['_id' => '10036']);
$restaurant = $database->restaurants->findOne([
'_id' => new MongoDB\BSON\ObjectID('594d5ef280a846852a4b3f70'),
])
Projecting Fields
~~~~~~~~~~~~~~~~~
The following example finds a restaurant based on the ``cuisine`` and The following example finds a restaurant based on the ``cuisine`` and
``borough`` fields and uses a :manual:`projection ``borough`` fields and uses a :manual:`projection
</tutorial/project-fields-from-query-results>` to limit the fields that are </tutorial/project-fields-from-query-results>` to limit the fields that are
...@@ -58,7 +80,7 @@ returned. ...@@ -58,7 +80,7 @@ returned.
.. code-block:: php .. code-block:: php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$restaurant = $collection->findOne( $restaurant = $collection->findOne(
[ [
......
...@@ -52,13 +52,13 @@ Examples ...@@ -52,13 +52,13 @@ Examples
-------- --------
The following example finds and deletes the document with ``restaurant_id`` of The following example finds and deletes the document with ``restaurant_id`` of
``"40375376"`` from the ``restaurants`` collection in the ``example`` database: ``"40375376"`` from the ``restaurants`` collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$deletedRestaurant = $collection->findOneAndDelete( $deletedRestaurant = $collection->findOneAndDelete(
[ 'restaurant_id' => '40375376' ], [ 'restaurant_id' => '40375376' ],
......
...@@ -54,7 +54,7 @@ Examples ...@@ -54,7 +54,7 @@ Examples
-------- --------
Consider the following document in the ``restaurants`` collection in the Consider the following document in the ``restaurants`` collection in the
``example`` database: ``test`` database:
.. code-block:: javascript .. code-block:: javascript
...@@ -99,7 +99,7 @@ The following operation replaces the document with ``restaurant_id`` of ...@@ -99,7 +99,7 @@ The following operation replaces the document with ``restaurant_id`` of
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->teset->restaurants;
$replacedRestaurant = $collection->findOneAndReplace( $replacedRestaurant = $collection->findOneAndReplace(
[ 'restaurant_id' => '41220906' ], [ 'restaurant_id' => '41220906' ],
......
...@@ -54,14 +54,14 @@ Examples ...@@ -54,14 +54,14 @@ Examples
-------- --------
The following operation updates the restaurant with ``restaurant_id`` of The following operation updates the restaurant with ``restaurant_id`` of
``"40361708"`` in the ``restaurants`` collection in the ``example`` database by ``"40361708"`` in the ``restaurants`` collection in the ``test`` database by
setting its building number to ``"761"``: setting its building number to ``"761"``:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$updatedRestaurant = $collection->findOneAndUpdate( $updatedRestaurant = $collection->findOneAndUpdate(
[ 'restaurant_id' => '40361708' ], [ 'restaurant_id' => '40361708' ],
......
...@@ -30,13 +30,13 @@ Example ...@@ -30,13 +30,13 @@ Example
------- -------
The following returns the collection name for the ``zips`` collection in the The following returns the collection name for the ``zips`` collection in the
``demo`` database. ``test`` database.
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
echo $collection->getCollectionName(); echo $collection->getCollectionName();
......
...@@ -30,19 +30,19 @@ Example ...@@ -30,19 +30,19 @@ Example
------- -------
The following returns the database name for the ``zips`` collection in the The following returns the database name for the ``zips`` collection in the
``demo`` database. ``test`` database.
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
echo $collection->getDatabaseName(); echo $collection->getDatabaseName();
The output would then resemble:: The output would then resemble::
demo test
See Also See Also
-------- --------
......
...@@ -30,20 +30,20 @@ The namespace of this collection as a string. ...@@ -30,20 +30,20 @@ The namespace of this collection as a string.
Example Example
------- -------
The following returns the namespace of the ``zips`` collection in the ``demo`` The following returns the namespace of the ``zips`` collection in the ``test``
database. database.
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
echo $collection->getNamespace(); echo $collection->getNamespace();
The output would then resemble:: The output would then resemble::
demo.zips test.zips
See Also See Also
-------- --------
......
...@@ -54,13 +54,13 @@ Example ...@@ -54,13 +54,13 @@ Example
.. start-crud-include .. start-crud-include
The following operation inserts two documents into the ``users`` collection The following operation inserts two documents into the ``users`` collection
in the ``example`` database: in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->users; $collection = (new MongoDB\Client)->test->users;
$insertManyResult = $collection->insertMany([ $insertManyResult = $collection->insertMany([
[ [
......
...@@ -53,13 +53,13 @@ Example ...@@ -53,13 +53,13 @@ Example
.. start-crud-include .. start-crud-include
The following operation inserts a document into the ``users`` collection in the The following operation inserts a document into the ``users`` collection in the
``example`` database: ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->users; $collection = (new MongoDB\Client)->test->users;
$insertOneResult = $collection->insertOne([ $insertOneResult = $collection->insertOne([
'username' => 'admin', 'username' => 'admin',
......
...@@ -45,13 +45,13 @@ Example ...@@ -45,13 +45,13 @@ Example
------- -------
The following example lists all of the indexes for the ``restaurants`` The following example lists all of the indexes for the ``restaurants``
collection in the ``example`` database: collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
foreach ($collection->listIndexes() as $index) { foreach ($collection->listIndexes() as $index) {
var_dump($index); var_dump($index);
...@@ -70,7 +70,7 @@ The output would then resemble:: ...@@ -70,7 +70,7 @@ The output would then resemble::
["name"]=> ["name"]=>
string(4) "_id_" string(4) "_id_"
["ns"]=> ["ns"]=>
string(19) "example.restaurants" string(16) "test.restaurants"
} }
object(MongoDB\Model\IndexInfo)#12 (4) { object(MongoDB\Model\IndexInfo)#12 (4) {
["v"]=> ["v"]=>
...@@ -83,7 +83,7 @@ The output would then resemble:: ...@@ -83,7 +83,7 @@ The output would then resemble::
["name"]=> ["name"]=>
string(10) "cuisine_-1" string(10) "cuisine_-1"
["ns"]=> ["ns"]=>
string(19) "example.restaurants" string(16) "test.restaurants"
} }
object(MongoDB\Model\IndexInfo)#8 (4) { object(MongoDB\Model\IndexInfo)#8 (4) {
["v"]=> ["v"]=>
...@@ -96,7 +96,7 @@ The output would then resemble:: ...@@ -96,7 +96,7 @@ The output would then resemble::
["name"]=> ["name"]=>
string(9) "borough_1" string(9) "borough_1"
["ns"]=> ["ns"]=>
string(19) "example.restaurants" string(16) "test.restaurants"
} }
See Also See Also
......
...@@ -55,13 +55,13 @@ Example ...@@ -55,13 +55,13 @@ Example
------- -------
The following example replaces the document with ``restaurant_id`` of The following example replaces the document with ``restaurant_id`` of
``"40356068"`` in the ``restaurants`` collection in the ``example`` database: ``"40356068"`` in the ``restaurants`` collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$updateResult = $collection->replaceOne( $updateResult = $collection->replaceOne(
[ 'restaurant_id' => '40356068' ], [ 'restaurant_id' => '40356068' ],
......
...@@ -57,7 +57,7 @@ The following example updates all of the documents with the ``borough`` of ...@@ -57,7 +57,7 @@ The following example updates all of the documents with the ``borough`` of
.. code-block:: php .. code-block:: php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$updateResult = $collection->updateMany( $updateResult = $collection->updateMany(
[ 'borough' => 'Queens' ], [ 'borough' => 'Queens' ],
......
...@@ -59,7 +59,7 @@ The following example updates one document with the ``restaurant_id`` of ...@@ -59,7 +59,7 @@ The following example updates one document with the ``restaurant_id`` of
.. code-block:: php .. code-block:: php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$updateResult = $collection->updateOne( $updateResult = $collection->updateOne(
[ 'restaurant_id' => '40356151' ], [ 'restaurant_id' => '40356151' ],
......
...@@ -49,7 +49,7 @@ preference: ...@@ -49,7 +49,7 @@ preference:
<?php <?php
$collection = (new MongoDB\Client)->selectCollect('demo', 'restaurants'); $collection = (new MongoDB\Client)->selectCollection('test', 'restaurants');
$newCollection = $sourceCollection->withOptions([ $newCollection = $sourceCollection->withOptions([
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY), 'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
......
...@@ -51,7 +51,7 @@ result document: ...@@ -51,7 +51,7 @@ result document:
<?php <?php
$database = (new MongoDB\Client)->example; $database = (new MongoDB\Client)->test;
$cursor = $database->command(['isMaster' => 1]); $cursor = $database->command(['isMaster' => 1]);
...@@ -92,7 +92,7 @@ multiple result documents: ...@@ -92,7 +92,7 @@ multiple result documents:
<?php <?php
$database = (new MongoDB\Client)->example; $database = (new MongoDB\Client)->test;
$cursor = $database->command(['isMaster' => 1]); $cursor = $database->command(['isMaster' => 1]);
......
...@@ -63,14 +63,14 @@ Errors/Exceptions ...@@ -63,14 +63,14 @@ Errors/Exceptions
Example Example
------- -------
The following example creates a ``users`` collection in the ``demo`` The following example creates a ``users`` collection in the ``test``
database with document validation criteria: database with document validation criteria:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$result = $db->createCollection('users', [ $result = $db->createCollection('users', [
'validator' => [ 'validator' => [
......
...@@ -46,13 +46,13 @@ Errors/Exceptions ...@@ -46,13 +46,13 @@ Errors/Exceptions
Example Example
------- -------
The following example drops the ``demo`` database: The following example drops the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$result = $db->drop(); $result = $db->drop();
...@@ -64,7 +64,7 @@ The output would then resemble:: ...@@ -64,7 +64,7 @@ The output would then resemble::
["storage":"ArrayObject":private]=> ["storage":"ArrayObject":private]=>
array(2) { array(2) {
["dropped"]=> ["dropped"]=>
string(4) "demo" string(4) "test"
["ok"]=> ["ok"]=>
float(1) float(1)
} }
......
...@@ -46,13 +46,13 @@ Errors/Exceptions ...@@ -46,13 +46,13 @@ Errors/Exceptions
Example Example
------- -------
The following example drops the ``users`` collection in the ``demo`` database: The following example drops the ``users`` collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$result = $db->dropCollection('users'); $result = $db->dropCollection('users');
...@@ -64,7 +64,7 @@ The output would then resemble:: ...@@ -64,7 +64,7 @@ The output would then resemble::
["storage":"ArrayObject":private]=> ["storage":"ArrayObject":private]=>
array(3) { array(3) {
["ns"]=> ["ns"]=>
string(10) "demo.users" string(10) "test.users"
["nIndexesWas"]=> ["nIndexesWas"]=>
int(1) int(1)
["ok"]=> ["ok"]=>
......
...@@ -35,10 +35,10 @@ The following example prints the name of a database object: ...@@ -35,10 +35,10 @@ The following example prints the name of a database object:
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
echo $db->getDatabaseName(); echo $db->getDatabaseName();
The output would then resemble:: The output would then resemble::
demo test
...@@ -39,13 +39,13 @@ database. ...@@ -39,13 +39,13 @@ database.
Example Example
------- -------
The following example lists all of the collections in the ``example`` database: The following example lists all of the collections in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$database = (new MongoDB\Client)->example; $database = (new MongoDB\Client)->test;
foreach ($database->listCollections() as $collectionInfo) { foreach ($database->listCollections() as $collectionInfo) {
var_dump($collectionInfo); var_dump($collectionInfo);
...@@ -76,13 +76,13 @@ The output would then resemble:: ...@@ -76,13 +76,13 @@ The output would then resemble::
} }
The following example lists all collections whose name starts with ``"rest"`` The following example lists all collections whose name starts with ``"rest"``
in the ``example`` database: in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$database = (new MongoDB\Client)->example; $database = (new MongoDB\Client)->test;
$collections = $database->listCollections([ $collections = $database->listCollections([
'filter' => [ 'filter' => [
......
...@@ -49,24 +49,24 @@ overridden via the ``$options`` parameter. ...@@ -49,24 +49,24 @@ overridden via the ``$options`` parameter.
Example Example
------- -------
The following example selects the ``users`` collection in the ``demo`` database: The following example selects the ``users`` collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$collection = $db->selectCollection('demo', 'users'); $collection = $db->selectCollection('test', 'users');
The following example selects the ``users`` collection in the ``demo`` The following example selects the ``users`` collection in the ``test``
database with a custom read preference: database with a custom read preference:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$users = $db->selectCollection( $users = $db->selectCollection(
'users', 'users',
......
...@@ -49,25 +49,25 @@ overridden via the ``$options`` parameter. ...@@ -49,25 +49,25 @@ overridden via the ``$options`` parameter.
Example Example
------- -------
The following example selects the default ``fs.files`` bucket in the ``demo`` The following example selects the default ``fs.files`` bucket in the ``test``
database: database:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$bucket = $db->selectGridFSBucket(); $bucket = $db->selectGridFSBucket();
The following example selects the custom ``images.files`` bucket in the ``demo`` The following example selects the custom ``images.files`` bucket in the ``test``
database with a custom read preference: database with a custom read preference:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$imagesBucket = $db->selectGridFSBucket([ $imagesBucket = $db->selectGridFSBucket([
'bucketName' => 'images', 'bucketName' => 'images',
......
...@@ -49,7 +49,7 @@ preference: ...@@ -49,7 +49,7 @@ preference:
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$newDb = $db->withOptions([ $newDb = $db->withOptions([
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY), 'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY),
......
...@@ -50,13 +50,13 @@ Examples ...@@ -50,13 +50,13 @@ Examples
-------- --------
The following example selects the ``users`` and ``system.profile`` The following example selects the ``users`` and ``system.profile``
collections from the ``demo`` database: collections from the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$users = $db->users; $users = $db->users;
$systemProfile = $db->{'system.profile'}; $systemProfile = $db->{'system.profile'};
......
...@@ -30,13 +30,13 @@ To execute a command on a :program:`mongod` instance, use the ...@@ -30,13 +30,13 @@ To execute a command on a :program:`mongod` instance, use the
:phpmethod:`MongoDB\\Database::command()` method. For instance, the following :phpmethod:`MongoDB\\Database::command()` method. For instance, the following
operation uses the :manual:`geoNear </reference/command/geoNear>` command to operation uses the :manual:`geoNear </reference/command/geoNear>` command to
search for the three closest documents to longitude ``-74`` and latitude ``40`` search for the three closest documents to longitude ``-74`` and latitude ``40``
in the ``restos`` collection in the ``example`` database: in the ``restos`` collection in the ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$database = (new MongoDB\Client)->example; $database = (new MongoDB\Client)->test;
$cursor = $database->command([ $cursor = $database->command([
'geoNear' => 'restos', 'geoNear' => 'restos',
...@@ -218,14 +218,14 @@ object on which it is invoked. To execute commands that require a specific read ...@@ -218,14 +218,14 @@ object on which it is invoked. To execute commands that require a specific read
preference, specify the read preference in the ``$options`` parameter of the preference, specify the read preference in the ``$options`` parameter of the
method. method.
The following example adds a user to the ``demo`` database and specifies a The following example adds a user to the ``test`` database and specifies a
custom read preference: custom read preference:
.. code-block:: php .. code-block:: php
<?php <?php
$db = (new MongoDB\Client)->demo; $db = (new MongoDB\Client)->test;
$cursor = $db->command( $cursor = $db->command(
[ [
...@@ -267,7 +267,7 @@ document, or access the first result in the array, as in the following: ...@@ -267,7 +267,7 @@ document, or access the first result in the array, as in the following:
<?php <?php
$database = (new MongoDB\Client)->demo; $database = (new MongoDB\Client)->test;
$cursor = $database->command(['ping' => 1]); $cursor = $database->command(['ping' => 1]);
...@@ -290,7 +290,7 @@ Some commands, such as :manual:`listCollections ...@@ -290,7 +290,7 @@ Some commands, such as :manual:`listCollections
</reference/command/listCollections>`, return their results via an iterable </reference/command/listCollections>`, return their results via an iterable
cursor. To view the results, iterate through the cursor. cursor. To view the results, iterate through the cursor.
The following example lists the collections in the ``demo`` database by The following example lists the collections in the ``test`` database by
iterating through the cursor returned by the ``listCollections`` command using a iterating through the cursor returned by the ``listCollections`` command using a
``foreach`` loop: ``foreach`` loop:
...@@ -298,7 +298,7 @@ iterating through the cursor returned by the ``listCollections`` command using a ...@@ -298,7 +298,7 @@ iterating through the cursor returned by the ``listCollections`` command using a
<?php <?php
$database = (new MongoDB\Client)->demo; $database = (new MongoDB\Client)->test;
$cursor = $database->command(['listCollections' => 1]); $cursor = $database->command(['listCollections' => 1]);
......
...@@ -53,7 +53,7 @@ The following example inserts a document while specifying the value for the ...@@ -53,7 +53,7 @@ The following example inserts a document while specifying the value for the
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$insertOneResult = $collection->insertOne(['_id' => 1, 'name' => 'Alice']); $insertOneResult = $collection->insertOne(['_id' => 1, 'name' => 'Alice']);
...@@ -107,7 +107,7 @@ The following example searches for the document with ``_id`` of ``"94301"``: ...@@ -107,7 +107,7 @@ The following example searches for the document with ``_id`` of ``"94301"``:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$document = $collection->findOne(['_id' => '94301']); $document = $collection->findOne(['_id' => '94301']);
...@@ -167,7 +167,7 @@ specified city and state values: ...@@ -167,7 +167,7 @@ specified city and state values:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$cursor = $collection->find(['city' => 'JERSEY CITY', 'state' => 'NJ']); $cursor = $collection->find(['city' => 'JERSEY CITY', 'state' => 'NJ']);
...@@ -210,7 +210,7 @@ returned. It also limits the results to 5 documents. ...@@ -210,7 +210,7 @@ returned. It also limits the results to 5 documents.
<?php <?php
$collection = (new MongoDB\Client)->example->restaurants; $collection = (new MongoDB\Client)->test->restaurants;
$cursor = $collection->find( $cursor = $collection->find(
[ [
...@@ -311,7 +311,7 @@ five most populous zip codes in the United States: ...@@ -311,7 +311,7 @@ five most populous zip codes in the United States:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$cursor = $collection->find( $cursor = $collection->find(
[], [],
...@@ -347,7 +347,7 @@ name starts with "garden" and the state is Texas: ...@@ -347,7 +347,7 @@ name starts with "garden" and the state is Texas:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$cursor = $collection->find([ $cursor = $collection->find([
'city' => new MongoDB\BSON\Regex('^garden', 'i'), 'city' => new MongoDB\BSON\Regex('^garden', 'i'),
...@@ -395,7 +395,7 @@ with them: ...@@ -395,7 +395,7 @@ with them:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$cursor = $collection->aggregate([ $cursor = $collection->aggregate([
['$group' => ['_id' => '$state', 'count' => ['$sum' => 1]]], ['$group' => ['_id' => '$state', 'count' => ['$sum' => 1]]],
...@@ -434,7 +434,7 @@ updates to perform. The :phpmethod:`MongoDB\\Collection::updateOne()` reference ...@@ -434,7 +434,7 @@ updates to perform. The :phpmethod:`MongoDB\\Collection::updateOne()` reference
describes each parameter in detail. describes each parameter in detail.
The following example inserts two documents into an empty ``users`` collection The following example inserts two documents into an empty ``users`` collection
in the ``demo`` database using the :phpmethod:`MongoDB\\Collection::insertOne()` in the ``test`` database using the :phpmethod:`MongoDB\\Collection::insertOne()`
method, and then updates the documents where the value for the ``state`` field method, and then updates the documents where the value for the ``state`` field
is ``"ny"`` to include a ``country`` field set to ``"us"``: is ``"ny"`` to include a ``country`` field set to ``"us"``:
...@@ -442,7 +442,7 @@ is ``"ny"`` to include a ``country`` field set to ``"us"``: ...@@ -442,7 +442,7 @@ is ``"ny"`` to include a ``country`` field set to ``"us"``:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
...@@ -470,7 +470,7 @@ value, as in this example: ...@@ -470,7 +470,7 @@ value, as in this example:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
...@@ -506,7 +506,7 @@ updates to perform. The :phpmethod:`MongoDB\\Collection::updateMany()` reference ...@@ -506,7 +506,7 @@ updates to perform. The :phpmethod:`MongoDB\\Collection::updateMany()` reference
describes each parameter in detail. describes each parameter in detail.
The following example inserts three documents into an empty ``users`` collection The following example inserts three documents into an empty ``users`` collection
in the ``demo`` database and then uses the :query:`$set` operator to update the in the ``test`` database and then uses the :query:`$set` operator to update the
documents matching the filter criteria to include the ``country`` field with documents matching the filter criteria to include the ``country`` field with
value ``"us"``: value ``"us"``:
...@@ -514,7 +514,7 @@ value ``"us"``: ...@@ -514,7 +514,7 @@ value ``"us"``:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny', 'country' => 'us']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny', 'country' => 'us']);
...@@ -567,13 +567,13 @@ parameter in detail. ...@@ -567,13 +567,13 @@ parameter in detail.
fields in a document rather than replacing the entire document. fields in a document rather than replacing the entire document.
The following example inserts one document into an empty ``users`` collection in The following example inserts one document into an empty ``users`` collection in
the ``demo`` database, and then replaces that document with a new one: the ``test`` database, and then replaces that document with a new one:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
...@@ -609,13 +609,13 @@ When a document is upserted, the ID is accessible via ...@@ -609,13 +609,13 @@ When a document is upserted, the ID is accessible via
The following example uses :phpmethod:`MongoDB\\Collection::updateOne()` with The following example uses :phpmethod:`MongoDB\\Collection::updateOne()` with
the ``upsert`` option set to ``true`` and an empty ``users`` collection in the the ``upsert`` option set to ``true`` and an empty ``users`` collection in the
``demo`` database, therefore inserting the document into the database: ``test`` database, therefore inserting the document into the database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$updateResult = $collection->updateOne( $updateResult = $collection->updateOne(
...@@ -681,7 +681,7 @@ value is ``"ny"``: ...@@ -681,7 +681,7 @@ value is ``"ny"``:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
...@@ -715,7 +715,7 @@ value is ``"ny"``: ...@@ -715,7 +715,7 @@ value is ``"ny"``:
<?php <?php
$collection = (new MongoDB\Client)->demo->users; $collection = (new MongoDB\Client)->test->users;
$collection->drop(); $collection->drop();
$collection->insertOne(['name' => 'Bob', 'state' => 'ny']); $collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
......
...@@ -36,7 +36,7 @@ field of a collection named ``inventory``: ...@@ -36,7 +36,7 @@ field of a collection named ``inventory``:
<?php <?php
$collection = (new MongoDB\Client)->demo->inventory; $collection = (new MongoDB\Client)->test->inventory;
$collection->insertOne([ $collection->insertOne([
'_id' => 1, '_id' => 1,
......
...@@ -5,38 +5,41 @@ Example Data ...@@ -5,38 +5,41 @@ Example Data
.. default-domain:: mongodb .. default-domain:: mongodb
Some examples in this documentation use example data fixtures from Some examples in this documentation use example data fixtures from
`zips.json <http://media.mongodb.org/zips.json>`_. This is a dataset comprised `zips.json <https://media.mongodb.org/zips.json>`_ and
of United States postal codes, populations, and geographic locations. `primer-dataset.json <https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/primer-dataset.json>`_.
Importing the dataset into MongoDB can be done in several ways. The following Importing the dataset into MongoDB can be done in several ways. The following
example uses the :php:`driver <mongodb>` directly: example imports the `zips.json` file into a `test.zips` collection:
:php:`driver <mongodb>` directly:
.. code-block:: php .. code-block:: php
<?php <?php
$file = 'http://media.mongodb.org/zips.json'; $filename = 'https://media.mongodb.org/zips.json';
$zips = file($file, FILE_IGNORE_NEW_LINES); $lines = file($filename, FILE_IGNORE_NEW_LINES);
$bulk = new MongoDB\Driver\BulkWrite; $bulk = new MongoDB\Driver\BulkWrite;
foreach ($zips as $string) { foreach ($lines as $line) {
$document = json_decode($string); $bson = MongoDB\BSON\fromJSON($line);
$document = MongoDB\BSON\toPHP($bson);
$bulk->insert($document); $bulk->insert($document);
} }
$manager = new MongoDB\Driver\Manager('mongodb://127.0.0.1/'); $manager = new MongoDB\Driver\Manager('mongodb://127.0.0.1/');
$result = $manager->executeBulkWrite('demo.zips', $bulk); $result = $manager->executeBulkWrite('test.zips', $bulk);
printf("Inserted %d documents\n", $result->getInsertedCount()); printf("Inserted %d documents\n", $result->getInsertedCount());
The output would then resemble:: The output would then resemble::
Inserted 29353 documents Inserted 29353 documents
You may also import the dataset using :manual:`mongoimport You may also import the datasets using :manual:`mongoimport
</reference/program/mongoimport>`, which is included with MongoDB: </reference/program/mongoimport>`, which is included with MongoDB:
.. code-block:: none .. code-block:: none
$ mongoimport --db demo --collection zips --file zips.json --drop $ mongoimport --db test --collection zips --file zips.json --drop
$ mongoimport --db test --collection restaurants --file primer-dataset.json --drop
...@@ -50,7 +50,7 @@ To open an upload stream and write to it: ...@@ -50,7 +50,7 @@ To open an upload stream and write to it:
<?php <?php
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openUploadStream('my-file.txt'); $stream = $bucket->openUploadStream('my-file.txt');
...@@ -64,7 +64,7 @@ To upload the entire contents of a readable stream in one call: ...@@ -64,7 +64,7 @@ To upload the entire contents of a readable stream in one call:
<?php <?php
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$file = fopen('/path/to/my-file.txt', 'rb'); $file = fopen('/path/to/my-file.txt', 'rb');
$bucket->uploadFromStream('my-file.txt', $file); $bucket->uploadFromStream('my-file.txt', $file);
...@@ -84,7 +84,7 @@ To open a download stream and read from it: ...@@ -84,7 +84,7 @@ To open a download stream and read from it:
// In practice, $fileId denotes the _id of an existing file in GridFS // In practice, $fileId denotes the _id of an existing file in GridFS
$fileId = new MongoDB\BSON\ObjectId; $fileId = new MongoDB\BSON\ObjectId;
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openDownloadStream($fileId); $stream = $bucket->openDownloadStream($fileId);
$contents = stream_get_contents($stream); $contents = stream_get_contents($stream);
...@@ -98,7 +98,7 @@ To download the file all at once and write it to a writable stream: ...@@ -98,7 +98,7 @@ To download the file all at once and write it to a writable stream:
// In practice, $fileId denotes the _id of an existing file in GridFS // In practice, $fileId denotes the _id of an existing file in GridFS
$fileId = new MongoDB\BSON\ObjectId; $fileId = new MongoDB\BSON\ObjectId;
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$file = fopen('/path/to/my-output-file.txt', 'wb'); $file = fopen('/path/to/my-output-file.txt', 'wb');
...@@ -133,7 +133,7 @@ particular file: ...@@ -133,7 +133,7 @@ particular file:
<?php <?php
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openDownloadStreamByName('my-file.txt', ['revision' => 0]); $stream = $bucket->openDownloadStreamByName('my-file.txt', ['revision' => 0]);
$contents = stream_get_contents($stream); $contents = stream_get_contents($stream);
...@@ -150,7 +150,7 @@ You can delete a GridFS file by its ``_id``. ...@@ -150,7 +150,7 @@ You can delete a GridFS file by its ``_id``.
// In practice, $fileId denotes the _id of an existing file in GridFS // In practice, $fileId denotes the _id of an existing file in GridFS
$fileId = new MongoDB\BSON\ObjectId; $fileId = new MongoDB\BSON\ObjectId;
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$bucket->delete($fileId); $bucket->delete($fileId);
...@@ -165,7 +165,7 @@ about the GridFS files. ...@@ -165,7 +165,7 @@ about the GridFS files.
<?php <?php
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$cursor = $bucket->find(['filename' => 'my-file.txt']); $cursor = $bucket->find(['filename' => 'my-file.txt']);
...@@ -183,7 +183,7 @@ the file document for an existing readable or writable GridFS stream. ...@@ -183,7 +183,7 @@ the file document for an existing readable or writable GridFS stream.
// In practice, $fileId denotes the _id of an existing file in GridFS // In practice, $fileId denotes the _id of an existing file in GridFS
$fileId = new MongoDB\BSON\ObjectId; $fileId = new MongoDB\BSON\ObjectId;
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openDownloadStream($fileId); $stream = $bucket->openDownloadStream($fileId);
$metadata = $bucket->getFileDocumentForStream($stream); $metadata = $bucket->getFileDocumentForStream($stream);
...@@ -208,7 +208,7 @@ convenience for accessing the ``_id`` property of the object returned by ...@@ -208,7 +208,7 @@ convenience for accessing the ``_id`` property of the object returned by
<?php <?php
$bucket = (new MongoDB\Client)->example->selectGridFSBucket(); $bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openDownloadStreamByName('my-file.txt'); $stream = $bucket->openDownloadStreamByName('my-file.txt');
$fileId = $bucket->getFileIdForStream($stream); $fileId = $bucket->getFileIdForStream($stream);
...@@ -37,7 +37,7 @@ the :phpmethod:`createIndex() <MongoDB\\Collection::createIndex>` method: ...@@ -37,7 +37,7 @@ the :phpmethod:`createIndex() <MongoDB\\Collection::createIndex>` method:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$result = $collection->createIndex(['state' => 1]); $result = $collection->createIndex(['state' => 1]);
...@@ -59,13 +59,13 @@ about the indexes in a collection. The ...@@ -59,13 +59,13 @@ about the indexes in a collection. The
information about each index. Refer to the method reference for more details. information about each index. Refer to the method reference for more details.
The following example lists all indexes in the ``zips`` collection in the The following example lists all indexes in the ``zips`` collection in the
``demo`` database: ``test`` database:
.. code-block:: php .. code-block:: php
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
foreach ($collection->listIndexes() as $indexInfo) { foreach ($collection->listIndexes() as $indexInfo) {
var_dump($indexInfo); var_dump($indexInfo);
...@@ -84,7 +84,7 @@ The output would resemble:: ...@@ -84,7 +84,7 @@ The output would resemble::
["name"]=> ["name"]=>
string(4) "_id_" string(4) "_id_"
["ns"]=> ["ns"]=>
string(9) "demo.zips" string(9) "test.zips"
} }
object(MongoDB\Model\IndexInfo)#13 (4) { object(MongoDB\Model\IndexInfo)#13 (4) {
["v"]=> ["v"]=>
...@@ -97,7 +97,7 @@ The output would resemble:: ...@@ -97,7 +97,7 @@ The output would resemble::
["name"]=> ["name"]=>
string(7) "state_1" string(7) "state_1"
["ns"]=> ["ns"]=>
string(9) "demo.zips" string(9) "test.zips"
} }
Drop Indexes Drop Indexes
...@@ -114,7 +114,7 @@ The following example drops a single index by its name, ``state_1``: ...@@ -114,7 +114,7 @@ The following example drops a single index by its name, ``state_1``:
<?php <?php
$collection = (new MongoDB\Client)->demo->zips; $collection = (new MongoDB\Client)->test->zips;
$result = $collection->dropIndex('state_1'); $result = $collection->dropIndex('state_1');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment