@@ -5,23 +5,25 @@ Example Data
5
5
.. default-domain:: mongodb
6
6
7
7
Some examples in this documentation use example data fixtures from
8
- `zips.json <http ://media.mongodb.org/zips.json>`_. This is a dataset comprised
9
- of United States postal codes, populations, and geographic locations .
8
+ `zips.json <https ://media.mongodb.org/zips.json>`_ and
9
+ `primer-dataset.json <https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/primer-dataset.json>`_ .
10
10
11
11
Importing the dataset into MongoDB can be done in several ways. The following
12
- example uses the :php:`driver <mongodb>` directly:
12
+ example imports the `zips.json` file into a `demo.zips` collection:
13
+ :php:`driver <mongodb>` directly:
13
14
14
15
.. code-block:: php
15
16
16
17
<?php
17
18
18
- $file = 'http ://media.mongodb.org/zips.json';
19
- $zips = file($file , FILE_IGNORE_NEW_LINES);
19
+ $filename = 'https ://media.mongodb.org/zips.json';
20
+ $lines = file($filename , FILE_IGNORE_NEW_LINES);
20
21
21
22
$bulk = new MongoDB\Driver\BulkWrite;
22
23
23
- foreach ($zips as $string) {
24
- $document = json_decode($string);
24
+ foreach ($lines as $line) {
25
+ $bson = MongoDB\BSON\fromJSON($line);
26
+ $document = MongoDB\BSON\toPHP($bson);
25
27
$bulk->insert($document);
26
28
}
27
29
@@ -34,9 +36,10 @@ The output would then resemble::
34
36
35
37
Inserted 29353 documents
36
38
37
- You may also import the dataset using :manual:`mongoimport
39
+ You may also import the datasets using :manual:`mongoimport
38
40
</reference/program/mongoimport>`, which is included with MongoDB:
39
41
40
42
.. code-block:: none
41
43
42
44
$ mongoimport --db demo --collection zips --file zips.json --drop
45
+ $ mongoimport --db demo --collection restaurants --file primer-dataset.json --drop
0 commit comments