简体   繁体   English

ArangoDB:如何将集合导出到CSV?

[英]ArangoDB: How to export collection to CSV?

I have noticed there is a feature in web interface of ArangoDB which allows users to Download or Upload data as JSON file. 我注意到ArangoDB的Web界面中有一个功能,该功能允许用户将数据下载或上传为JSON文件。 However, I find nothing similar for CSV exporting. 但是,我发现CSV导出没有类似之处。 How can an existing Arango DB collection be exported to a .csv file? 如何将现有的Arango DB集合导出到.csv文件?

If you want to export data from ArangoDB to CSV, then you should use Arangoexport . 如果要将数据从ArangoDB导出到CSV,则应使用Arangoexport It is included in the full packages as well as the client-only packages. 它包含在完整软件包以及仅客户端软件包中。 You find it next to the arangod server executable. 您可以在arangod服务器可执行文件旁边找到它。

Basic usage: 基本用法:
https://docs.arangodb.com/3.4/Manual/Programs/Arangoexport/Examples.html#export-csv https://docs.arangodb.com/3.4/Manual/Programs/Arangoexport/Examples.html#export-csv

Also see the CSV example with AQL query: 另请参阅带有AQL查询的CSV示例:
https://docs.arangodb.com/3.4/Manual/Programs/Arangoexport/Examples.html#export-via-aql-query https://docs.arangodb.com/3.4/Manual/Programs/Arangoexport/Examples.html#export-via-aql-query

Using an AQL query for a CSV export allows you to transform the data if desired, eg to concatenate an array to a string or unpack nested objects. 通过将AQL查询用于CSV导出,可以根据需要转换数据,例如将数组连接为字符串或解压缩嵌套对象。 If you don't do that, then the JSON serialization of arrays/objects will be exported (which may or may not be what you want). 如果不这样做,则将导出数组/对象的JSON序列化(可能是您想要的也可能不是)。

The default Arango install includes the following file: Arango的默认安装包括以下文件:

/usr/share/arangodb3/js/contrib/CSV_export/CSVexport.js

It includes this comment: 它包含以下注释:

// This is a generic CSV exporter for collections.
//
// Usage: Run with arangosh like this:
//   arangosh --javascript.execute <CollName> [ <Field1> <Field2> ... ]

Unfortunately, at least in my experience, that usage tip is incorrect . 不幸的是,至少以我的经验来看,该用法提示是不正确的 Arango team, if you are reading this, please correct the file or correct my understanding. Arango小组,如果您正在阅读此文件,请更正文件或更正我的理解。

Here's how I got it to work: 这是我如何使其工作的方法:

arangosh --javascript.execute "/usr/share/arangodb3/js/contrib/CSV_export/CSVexport.js" "<CollectionName>"
Please specify a password: 

Then it sends the CSV data to stdout. 然后,它将CSV数据发送到stdout。 (If you with to send it to a file, you have to deal with the password prompt in some way.) (如果要将其发送到文件,则必须以某种方式处理密码提示。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM