首页 > 解决方案 > 如何将json文件中的json值插入orientdb

问题描述

我是 orientDB 的新手。我想知道如何将 json 文件中的 json 值插入到 orientDB 中。

{   "config": {
    "log": "debug"   },   "source" : {
    "file": { "path": "D:\\New folder\\database.json" }   },   "extractor" : {
    "json": {}   },   "transformers" : [
    { "merge": { "joinFieldName": "id", "lookup": "Account.id" } },
    { "vertex": { "class": "Account"} },
    { "edge": {
      "class": "Friend",
      "joinFieldName": "friends",
      "lookup": "Account.id",
      "unresolvedLinkAction": "CREATE"
    } },
    { "edge": {
      "class": "Enemy",
      "joinFieldName": "enemies",
      "lookup": "Account.id",
      "unresolvedLinkAction": "CREATE"
    } }   ],   "loader" : {
    "orientdb": {
      "dbURL": "D:\\InstalledSoftwares\\orientdb-3.0.8\\databases\\demodb",
      "dbUser": "root",
      "dbPassword": "vtg@123",
      "dbAutoDropIfExists": true,
      "dbAutoCreate": true,
      "standardElementConstraints": false,
      "tx": false,
      "wal": false,
      "batchCommit": 1000,
      "dbType": "graph",
      "classes": [{"name": "Account", "extends":"V"}, {"name": "Friend", "extends":"E"}, {"name": 'Enemy', "extends":"E"}],
      "indexes": [{"class":"Account", "fields":["id:integer"], "type":"UNIQUE_HASH_INDEX" }]
    }   } }

这是我用来从 json 文件中插入 json 值的代码。如果我运行此代码意味着它会引发错误,例如

java.lang.IllegalArgumentException:文本不能为空

你能验证一下并帮我解决这个问题吗?提前致谢

标签: orientdborientdb2.2orientdb-2.1

解决方案


我试过你的案子,它奏效了

数据库.json

[ 
    { 
        "name": "Joe", 
        "id": 1, 
        "friends": [2,4,5], 
        "enemies": [6] 
    }, 
    { 
        "name": "Suzie", 
        "id": 2, 
        "friends": [1,4,6], 
        "enemies": [5,2] 
    } 
]


导入.json

{   
  "config": {
    "log": "debug"   
  },
  "source" : {
    "file": { "path": "database.json" }   
  },
  "extractor" : {
    "json": {}   
  },
  "transformers" : [
    { "merge": { "joinFieldName": "id", "lookup": "Account.id" } },
    { "vertex": { "class": "Account"} },
    { "edge": {
      "class": "Friend",
      "joinFieldName": "friends",
      "lookup": "Account.id",
      "unresolvedLinkAction": "CREATE"
    } },
    { "edge": {
      "class": "Enemy",
      "joinFieldName": "enemies",
      "lookup": "Account.id",
      "unresolvedLinkAction": "CREATE"
    } }   ],   "loader" : {
    "orientdb": {
      "dbURL": "remote:localhost/db_name",
      "serverUser": "server_username",
      "serverPassword": "server_password",
      "dbUser": "db_username",
      "dbPassword": "db_password",
      "dbAutoDropIfExists": true,
      "dbAutoCreate": true,
      "standardElementConstraints": false,
      "tx": false,
      "wal": false,
      "batchCommit": 1000,
      "dbType": "graph",
      "classes": [{"name": "Account", "extends":"V"}, {"name": "Friend", "extends":"E"}, {"name": 'Enemy', "extends":"E"}],
      "indexes": [{"class":"Account", "fields":["id:integer"], "type":"UNIQUE_HASH_INDEX" }]
    }   } }

然后我运行了 oetl.bat import.json 这就是我得到的:

select from V
+----+-----+-------+----+-------------+-----+-------+-------+-------------------+-------------+--------+
|#   |@RID |@CLASS |id  |in_Friend    |name |friends|enemies|out_Friend         |out_Enemy    |in_Enemy|
+----+-----+-------+----+-------------+-----+-------+-------+-------------------+-------------+--------+
|0   |#17:0|Account|2   |[#21:0]      |Suzie|[1,4,6]|[5,2]  |[#24:0,#21:1,#22:1]|[#26:0,#27:0]|[#27:0] |
|1   |#17:1|Account|6   |[#22:1]      |     |       |       |                   |             |[#25:0] |
|2   |#18:0|Account|1   |[#24:0]      |Joe  |[2,4,5]|[6]    |[#21:0,#22:0,#23:0]|[#25:0]      |        |
|3   |#19:0|Account|4   |[#22:0,#21:1]|     |       |       |                   |             |        |
|4   |#20:0|Account|5   |[#23:0]      |     |       |       |                   |             |[#26:0] |
+----+-----+-------+----+-------------+-----+-------+-------+-------------------+-------------+--------+


希望能帮助到你

问候


推荐阅读