File tree Expand file tree Collapse file tree 3 files changed +43
-45
lines changed Expand file tree Collapse file tree 3 files changed +43
-45
lines changed Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ Tutorials
9
9
/tutorial/commands
10
10
/tutorial/gridfs
11
11
/tutorial/indexes
12
+ /tutorial/example-data
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ ============
2
+ Example Data
3
+ ============
4
+
5
+ .. default-domain:: mongodb
6
+
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.
10
+
11
+ Importing the dataset into MongoDB can be done in several ways. The following
12
+ example uses the :php:`driver <mongodb>` directly:
13
+
14
+ .. code-block:: php
15
+
16
+ <?php
17
+
18
+ $file = 'http://media.mongodb.org/zips.json';
19
+ $zips = file($file, FILE_IGNORE_NEW_LINES);
20
+
21
+ $bulk = new MongoDB\Driver\BulkWrite;
22
+
23
+ foreach ($zips as $string) {
24
+ $document = json_decode($string);
25
+ $bulk->insert($document);
26
+ }
27
+
28
+ $manager = new MongoDB\Driver\Manager('mongodb://127.0.0.1/');
29
+
30
+ $result = $manager->executeBulkWrite('demo.zips', $bulk);
31
+ printf("Inserted %d documents\n", $result->getInsertedCount());
32
+
33
+ The output would then resemble::
34
+
35
+ Inserted 29353 documents
36
+
37
+ You may also import the dataset using :manual:`mongoimport
38
+ </reference/program/mongoimport>`, which is included with MongoDB:
39
+
40
+ .. code-block:: none
41
+
42
+ $ mongoimport --db demo --collection zips --file zips.json --drop
You can’t perform that action at this time.
0 commit comments