Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
7cf97e21
Commit
7cf97e21
authored
Jun 23, 2017
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add restaurants.json to example data documentation
parent
c6c000b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
example-data.txt
docs/tutorial/example-data.txt
+11
-8
No files found.
docs/tutorial/example-data.txt
View file @
7cf97e21
...
@@ -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 comprise
d
`zips.json <http
s://media.mongodb.org/zips.json>`_ an
d
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';
$file
name = 'https
://media.mongodb.org/zips.json';
$
zips = file($fil
e, FILE_IGNORE_NEW_LINES);
$
lines = file($filenam
e, 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 dataset
s
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment