RethinkDB - Import Data

Before you can import data into the database, you need to have the python driver. This can easily be installed through pip, pythons package manager.

Install pip if you haven't got it already.

sudo apt-get install python-pip -y

Install the driver through pip.

sudo pip install rethinkdb

Now you can import your data. To import a JSON file, execute something like below:

rethinkdb import -f input.json \
--format json \
--table test.accidents \
--pkey "Accident_Index"

RethinkDB also supports importing csv files.

rethinkdb import -f input.csv \
--format csv \
--table test.accidents \
--pkey "Accident_Index"
  • If the first line in a CSV file does not have the headers, then you need to specify --no-header
  • The primary key (--pkey) option is optional.
  • You can specify --custom-header for a custom header.
  • If you aren't using a comma for a delimiter, you can specify a custom one with --delimiter.

More information about the various import options can be found here.

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.