Skip to content

Instantly share code, notes, and snippets.

@korczis
Last active May 5, 2020 01:47
Show Gist options
  • Save korczis/2be371aedfb2575f6b9c to your computer and use it in GitHub Desktop.
Save korczis/2be371aedfb2575f6b9c to your computer and use it in GitHub Desktop.
Import separate json files into couchdb
#! /usr/bin/env bash
# HOWTO
#
# 0. Try this - wget https://gist.githubusercontent.com/korczis/2be371aedfb2575f6b9c/raw/82dd096034ab7a67371bb3aab4b1c3be97477df5/import-data.sh && chmod 755 ./import-data.sh && ./import-data.sh
#
# If the step "0" not works for you try following these steps
#
# 1. download this bash script to firmy.cz
# 2. make sure all data are in subfolder "data"
# 3. make sure you have couchdb up and running
# 4. make sure you have created database "firmy"
# 5. modify credentials if required
# 6. run this script "./import-data.sh"
# Credentials
USERNAME=apollo
PASSWORD=apollo
HOST=localhost
PORT=5984
DBNAME=firmy
DATA_FOLDER=data
for f in `ls $DATA_FOLDER`
do
DOC_PATH=$DATA_FOLDER/$f
# echo "$DOC_PATH"
# cat "$DOC_PATH"
curl -X POST -d "@$DOC_PATH" -H "Content-Type: application/json" http://$USERNAME:$PASSWORD@$HOST:$PORT/$DBNAME/
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment