Skip to content

Commit 0040abe

Browse files
committed
MM feedback, code edits
1 parent b41fef9 commit 0040abe

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

source/includes/read/limit-skip-sort.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
require 'vendor/autoload.php';
44

5-
$client = new MongoDB\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);
67

78
// start-db-coll
8-
$db = $client->sample_restaurants;
9-
$collection = $db->restaurants;
9+
$collection = $client->sample_restaurants->restaurants;
1010
// end-db-coll
1111

1212
// Retrieves 5 documents that have a "cuisine" value of "Italian"
1313
// start-limit
14-
$options = [
15-
'limit' => 5,
16-
];
17-
$cursor = $collection->find(['cuisine' => 'Italian'], $options);
14+
$cursor = $collection->find(
15+
['cuisine' => 'Italian'],
16+
['limit' => 5]
17+
);
1818

1919
foreach ($cursor as $doc) {
2020
echo json_encode($doc) . PHP_EOL;
@@ -23,23 +23,23 @@
2323

2424
// Retrieves documents with a "cuisine" value of "Italian" and sorts in ascending "name" order
2525
// start-sort
26-
$options = [
27-
'sort' => ['name' => 1],
28-
];
26+
$cursor = $collection->find(
27+
['cuisine' => 'Italian'],
28+
['sort' => ['name' => 1]]
29+
);
2930

30-
$cursor = $collection->find(['cuisine' => 'Italian'], $options);
3131
foreach ($cursor as $doc) {
3232
echo json_encode($doc) . PHP_EOL;
3333
}
3434
// end-sort
3535

3636
// Retrieves documents with a "borough" value of "Manhattan" but skips the first 10 results
3737
// start-skip
38-
$options = [
39-
'skip' => 10,
40-
];
38+
$cursor = $collection->find(
39+
['borough' => 'Manhattan'],
40+
['skip' => 10]
41+
);
4142

42-
$cursor = $collection->find(['borough' => 'Manhattan'], $options);
4343
foreach ($cursor as $doc) {
4444
echo json_encode($doc) . PHP_EOL;
4545
}
@@ -59,5 +59,3 @@
5959
echo json_encode($doc) . PHP_EOL;
6060
}
6161
// end-limit-sort-skip
62-
63-
?>

source/read/specify-documents-to-return.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Sample Data
3636
The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants``
3737
database from the :atlas:`Atlas sample datasets </sample-data>`. To access this collection
3838
from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster
39-
and assign the following values to your ``db`` and ``collection`` variables:
39+
and assign the following value to your ``collection`` variable:
4040

4141
.. literalinclude:: /includes/read/limit-skip-sort.php
4242
:language: php

0 commit comments

Comments
 (0)