<commit_before>============
Example Data
============

.. default-domain:: mongodb

Some examples in this documentation use example data fixtures from
`zips.json <http://media.mongodb.org/zips.json>`_. This is a dataset comprised
of United States postal codes, populations, and geographic locations.

Importing the dataset into MongoDB can be done in several ways. The following
example uses the :php:`driver <mongodb>` directly:

.. code-block:: php

   <?php

   $file = 'http://media.mongodb.org/zips.json';
   $zips = file($file, FILE_IGNORE_NEW_LINES);

   $bulk = new MongoDB\Driver\BulkWrite;

   foreach ($zips as $string) {
       $document = json_decode($string);
       $bulk->insert($document);
   }

   $manager = new MongoDB\Driver\Manager('mongodb://1192.168.3.11/');

   $result = $manager->executeBulkWrite('demo.zips', $bulk);
   printf("Inserted %d documents\n", $result->getInsertedCount());

The output would then resemble::

   Inserted 29353 documents

You may also import the dataset using :manual:`mongoimport
</reference/program/mongoimport>`, which is included with MongoDB:

.. code-block:: none

   $ mongoimport --db demo --collection zips --file zips.json --drop<commit_msg>Add restaurants.json to example data documentation<commit_after>============
Example Data
============

.. default-domain:: mongodb

Some examples in this documentation use example data fixtures from
`zips.json <https://media.mongodb.org/zips.json>`_ and
`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
example imports the `zips.json` file into a `demo.zips` collection:
:php:`driver <mongodb>` directly:

.. code-block:: php

   <?php

   $filename = 'https://media.mongodb.org/zips.json';
   $lines = file($filename, FILE_IGNORE_NEW_LINES);

   $bulk = new MongoDB\Driver\BulkWrite;

   foreach ($lines as $line) {
       $bson = MongoDB\BSON\fromJSON($line);
       $document = MongoDB\BSON\toPHP($bson);
       $bulk->insert($document);
   }

   $manager = new MongoDB\Driver\Manager('mongodb://127.0.0.1/');

   $result = $manager->executeBulkWrite('demo.zips', $bulk);
   printf("Inserted %d documents\n", $result->getInsertedCount());

The output would then resemble::

   Inserted 29353 documents

You may also import the datasets using :manual:`mongoimport
</reference/program/mongoimport>`, which is included with MongoDB:

.. code-block:: none

   $ mongoimport --db demo --collection zips --file zips.json --drop
   $ mongoimport --db demo --collection restaurants --file primer-dataset.json --drop
{'fraction_non_alphanumeric': 0.14919203307027434, 'fraction_numerical': 0.00977076287110109, 'mean_word_length': 4.070476190476191, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6062048', 'n_tokens_mistral': 869, 'n_tokens_neox': 798, 'n_words': 229}