1
0
Fork 0
arangodb/Doxygen/doc/ImpManualBasics.html

54 lines
5.7 KiB
HTML

<html><head><title>ArangoDB Manual</title> <style media="screen" type="text/css" style="display:none">body{background-color:white;font:13px Helvetica,arial,freesans,clean,sans-serif;line-height:1.4;color:#333;}#access{font-size:16px;margin-left:12px;display:block;margin-left:10px;margin-right:10px;background-color:#F3F1EE!important;}#access a{border-right:1px solid #DBDEDF;color:#A49F96;display:block;line-height:38px;padding:0 10px;text-decoration:none;}#navigation ul{text-transform:uppercase;list-style:none;margin:0;}#navigation li{float:left;position:relative;}#container{width:920px;margin:0 auto;}a{color:#4183C4;text-decoration:none;}.contents h2{font-size:24px;border-bottom:1px solid #CCC;color:black;}.contents h1{font-size:33px;border-bottom:1px solid #CCC;color:black;}.clearfix:after{content:".";display:block;clear:both;font-size:0;height:0;visibility:hidden;}/**/ *:first-child+html .clearfix{min-height:0;}/**/ * html .clearfix{height:1%;}</style></head><body><div id="container"><img src="images/logo_arangodb.png" width="397" height="67" alt="ArangoDB"><div id="access" role="navigation"><div id="navigation"><ul id="menu-ahome" class="menu"><li><a href="Home.html">Table of contents</a></li> <li><a href="http://www.arangodb.org">ArangoDB homepage</a></li></ul></div><div class="clearfix"></div></div><div>
<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div class="header">
<div class="headertitle">
<h1>ArangoDB Importer </h1> </div>
</div>
<div class="contents">
<div class="textblock"><p>This manual describes the ArangoDB importer <code>arangoimp</code>, which can be used for bulk imports.</p>
<hr/>
<ul>
<li>
<a class="el" href="ImpManualBasics.html">ArangoDB Importer</a> <ul>
<li>
<a class="el" href="ImpManualBasics.html#ImpManualBasicsJson">Importing JSON-encoded Data</a> </li>
<li>
<a class="el" href="ImpManualBasics.html#ImpManualBasicsCsv">Importing CSV Data</a> </li>
</ul>
</li>
</ul>
<hr/>
The most convenient method to import a lot of data into ArangoDB is to use the <code>arangoimp</code> command-line tool. It allows you to import data records from a file into an existing database collection.</p>
<p>Let's assume you want to import user records into an existing collection named "users" on the server.</p>
<h2><a class="anchor" id="ImpManualBasicsJson"></a>
Importing JSON-encoded Data</h2>
<p>Let's further assume the import at hand is encoded in JSON. We'll be using these example user records to import:</p>
<div class="fragment"><pre class="fragment">{ "name" : { "first" : "John", "last" : "Connor" }, "active" : true, "age" : 25, "likes" : [ "swimming"] }
{ "name" : { "first" : "Jim", "last" : "O'Brady" }, "age" : 19, "likes" : [ "hiking", "singing" ] }
{ "name" : { "first" : "Lisa", "last" : "Jones" }, "dob" : "1981-04-09", "likes" : [ "running" ] }
</pre></div><p>To import these records, all you need to do is to put them into a file (with one line for each record to import) and run the following command:</p>
<p><code>./arangoimp --file "data.json" --type json --collection "users"</code></p>
<p>This will transfer the data to the server, import the records, and print a status summary.</p>
<p>By default, the endpoint <code>tcp://127.0.0.1:8529</code> will be used. If you want to specify a different endpoint, you can use the --server.endpoint option. You probably want to specify a database user and password as well. You can do so by using the options --server.username and --server.password. If you do not specify a password, you will be prompted for one.</p>
<p><code>./arangoimp --server.endpoint tcp://127.0.0.1:8529 --server.username root --file "data.json" --type json --collection "users"</code></p>
<p>Note that the collection (<code>users</code> in this case) must already exist or the import will fail. If you want to create a new collection with the import data, you need to specify the --create-collection option.</p>
<p><code>./arangoimp --file "data.json" --type json --collection "users" --create-collection true</code></p>
<p>As the import file already contains the data in JSON format, attribute names and data types are fully preserved. As can be seen in the example data, there is no need for all data records to have the same attribute names or types. Records can be inhomogenous.</p>
<h2><a class="anchor" id="ImpManualBasicsCsv"></a>
Importing CSV Data</h2>
<p><code>arangoimp</code> also offers the possibility to import data from CSV files. This comes handy when the data at hand is in CSV format already and you don't want to spend time converting them to JSON for the import.</p>
<p>To import data from a CSV file, make sure your file contains the attribute names in the first row. All the following lines in the file will be interpreted as data records and will be imported.</p>
<p>The CSV import requires the data to have a homogenuous struct. All records must have exactly the same amount of columns as there are headers.</p>
<p>The cell values can have different data types though. If a cell does not have any value, it can be left empty in the file. These values will not be imported so the attributes will not "be there" in document created. Values enclosed in quotes will be imported as strings, so to import numeric values, boolean values or the null value, don't enclose the value into the quotes in your file.</p>
<p>We'll be using the following import for the CSV import:</p>
<div class="fragment"><pre class="fragment">"first","name","age","active","dob"
"John","Connor",25,true,
"Jim","O'Brady",19,,
"Lisa","Jones",,,"1981-04-09"
</pre></div><p>The command line to execute the import then is:</p>
<p><code>arangoimp --file "data.csv" --type csv --collection "users"</code></p>
<p>Note that the quote and separator characters can be adjusted via the <em>--quote</em> and <em>--separator</em> arguments when invoking arangoimp. </p>
</div></div>
</div></body></html>