我可以将csv导入集合并在ArangoDB中一次性将其链接到另一个集合吗?

问题描述 投票:0回答:1

我有2个CSV文件,它们是关系数据库的导出。 CSV1具有唯一ID, CSV2没有,但有一列链接到CSV1对象。 我导入CSV1将唯一ID映射到_key。 我想将CSV2导入另一个集合,并通过边缘将其链接到第一个集合中的对象。 最简单的方法是什么?

附: (我知道在Neo4j中,这样的事情使用导入工具是微不足道的,并且想知道ArangoDB中是否存在这样的功能,或者我将不得不编写一些AQL来执行此操作)。

真诚的,卖

csv arangodb
1个回答
1
投票

虽然没有向导来导入数据,但是假设您对命令行感到满意,那么将数据导入ArangoDB也是微不足道的(因为您在本网站,我打赌你是这样):

  1. 使用Arango导入工具将CSV文件导入两个集合
  2. 创建边缘集合
  3. 使用简单的AQL查询将数据插入边集合

以下是使用arangoimp导入csv的示例语法:

arangoimp --file <path/filename> --collection <collectionName> --create-collection true --type csv --server.database <databaseName> —server.username <username>

这里有一些常见的选择:

翻译列名:

arangoimport --file "data.csv" --type csv --translate "from=_from" --translate "to=_to"

忽略空值(而不是抛出警告而不是加载数据),使用标志:

--ignore-missing

忽略导入文件中的列:

arangoimport --file "data.csv" --type csv --remove-attribute “attributeName”

此外,如果您已在csv文件中拥有边集合,则还可以直接导入该集合:

arangoimp --file <path/filename> --collection <collectionName> --create-collection true --type csv --create-collection-type edge --server.database <databaseName>

最后,请注意,如果您在那里感觉更舒服,可以在Arango GUI中完成上面列表中的2和3。 3的陈述可能是这样的

let newEdges = ( for csv1rec in csv1_collection
                  for csv2rec in csv2_collection
                  filter csv1rec.id = csv2rec.colA
                return {from : csv1rec.id , to : csv2rec.colA} )
for rec in newEdges
insert {_from: rec.from, _to: rec.to} in edgeCollection

请注意,我正在从内存中为第3步编写AQL,因此可能需要稍微调整一下。

© www.soinside.com 2019 - 2024. All rights reserved.