File tree Expand file tree Collapse file tree 4 files changed +6
-11
lines changed Expand file tree Collapse file tree 4 files changed +6
-11
lines changed Original file line number Diff line number Diff line change 2
2
3
3
require 'vendor/autoload.php ' ;
4
4
5
- use MongoDB \Client ;
6
-
7
- $ client = new Client ('<connection string> ' );
5
+ $ uri = getenv ('MONGODB_URI ' ) ?: throw new RuntimeException ('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset ' );
6
+ $ client = new MongoDB \Client ($ uri );
8
7
9
8
// start-db-coll
10
- $ db = $ client ->sample_restaurants ;
11
- $ collection = $ db ->restaurants ;
9
+ $ collection = $ client ->sample_restaurants ->restaurants ;
12
10
// end-db-coll
13
11
14
12
// Retrieves documents matching the "name" field query and projects their "name", "cuisine", and "borough" values
59
57
echo json_encode ($ doc ) . PHP_EOL ;
60
58
}
61
59
// end-project-exclude
62
-
63
- ?>
Original file line number Diff line number Diff line change 5
5
$ client = new MongoDB \Client ($ uri );
6
6
7
7
// start-db-coll
8
- $ db = $ client ->sample_training ;
9
- $ collection = $ db ->companies ;
8
+ $ collection = $ client ->sample_training ->companies ;
10
9
// end-db-coll
11
10
12
11
// Finds one document with a "name" value of "LinkedIn"
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ Sample Data
30
30
The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants``
31
31
database from the :atlas:`Atlas sample datasets </sample-data>`. To access this collection
32
32
from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster
33
- and assign the following values to your ``db`` and `` collection`` variables :
33
+ and assign the following value to your ``collection`` variable :
34
34
35
35
.. literalinclude:: /includes/read/project.php
36
36
:language: php
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ Sample Data
31
31
The examples in this guide use the ``companies`` collection in the ``sample_training``
32
32
database from the :atlas:`Atlas sample datasets </sample-data>`. To access this collection
33
33
from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster
34
- and assign the following values to your ``db`` and `` collection`` variables :
34
+ and assign the following value to your ``collection`` variable :
35
35
36
36
.. literalinclude:: /includes/read/retrieve.php
37
37
:language: php
You can’t perform that action at this time.
0 commit comments