PHP Classes

File: vendor/mongodb/mongodb/docs/tutorial/example-data.txt

Recommend this page to a friend!
  Classes of LAGGOUNE Walid   MongoDB Queue PHP Query Execute   vendor/mongodb/mongodb/docs/tutorial/example-data.txt   Download  
File: vendor/mongodb/mongodb/docs/tutorial/example-data.txt
Role: Documentation
Content type: text/plain
Description: Documentation
Class: MongoDB Queue PHP Query Execute
Query and execute multiple queries using MongoDB
Author: By
Last change:
Date: 4 years ago
Size: 1,393 bytes
 

Contents

Class file image Download
============ 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 `test.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('test.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 test --collection zips --file zips.json --drop $ mongoimport --db test --collection restaurants --file primer-dataset.json --drop