-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingleinsert.php
42 lines (36 loc) · 1.06 KB
/
singleinsert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Created by PhpStorm.
* User: lynseylin
* Date: 2017/8/7
* Time: 上午11:43
*/
require 'config.php';
require __DIR__ . '/vendor/autoload.php';
use Wikibase\JsonDumpReader\JsonDumpFactory;
set_time_limit(0);
$factory = new JsonDumpFactory();
$dumpReader = $factory->newExtractedDumpReader(JSON_FILE);
$dumpIterator = $factory->newStringDumpIterator($dumpReader);
$client = new MongoDB\Client(MONGODB_SERVER);
$itemsCollection = $client->wikidata->items;
$propertiesCollection = $client->wikidata->properties;
$itemList = [];
$propertyList = [];
foreach ( $dumpIterator as $jsonLine ) {
$item = json_decode($jsonLine, true);
$id = $item["id"];
$item["_id"] = $id;
try {
if ($item["type"] == "item") {
$result = $itemsCollection->insertOne($item);
} else {
$result = $propertiesCollection->insertOne($item);
}
var_dump($result->getInsertedId());
} catch(Exception $e){
$message = $e->getMessage();
$code = $e->getCode();
printf("error:%s\n", $message);
}
}