Commit 7cf97e21 authored by Jeremy Mikola's avatar Jeremy Mikola

Add restaurants.json to example data documentation

parent c6c000b3
...@@ -5,23 +5,25 @@ Example Data ...@@ -5,23 +5,25 @@ 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 `demo.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);
} }
...@@ -34,9 +36,10 @@ The output would then resemble:: ...@@ -34,9 +36,10 @@ 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 demo --collection zips --file zips.json --drop
$ mongoimport --db demo --collection restaurants --file primer-dataset.json --drop
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