Browse Source

Got mongo init-db working

Jim Barritt 11 months ago
parent
commit
30bda9ea97

+ 3 - 3
apps/petitions/decode-app/ops/local/decode-app.sh

@@ -58,10 +58,10 @@ function init-db {
58 58
     echo -e "Database is clean."
59 59
 
60 60
     echo -e "\nImporting sample data to database [${DECODE_APP_DB_NAME}]...\n"
61
-    mongo/import ${DECODE_APP_DB_NAME} ${SCRIPT_HOME}/../sample-data/users.json
62
-    mongo/import ${DECODE_APP_DB_NAME} ${SCRIPT_HOME}/../sample-data/petitions.json
61
+    mongo/import ${DECODE_APP_DB_NAME} users ${SCRIPT_HOME}/../sample-data/users.json
62
+    mongo/import ${DECODE_APP_DB_NAME} petitions ${SCRIPT_HOME}/../sample-data/petitions.json
63 63
 
64
-    echo -e "\nDatabase is initialised."
64
+    echo -e "\nDatabase is initialised.\n"
65 65
 }
66 66
 
67 67
 

+ 7 - 7
apps/petitions/decode-app/ops/local/mongo.lib.sh

@@ -23,7 +23,7 @@ function mongo/eval {
23 23
     DB_NAME=$1
24 24
     MONGO_CMD=$2
25 25
     echo -e "mongo/eval ${MONGO_CMD}"
26
-    mongo $(mongo/connection ${DB_NAME}) --eval ${MONGO_CMD}
26
+    mongo $(mongo/connection ${DB_NAME}) --eval ${MONGO_CMD} --quiet
27 27
 }
28 28
 
29 29
 function mongo/db-exists? {
@@ -35,10 +35,10 @@ function mongo/db-exists? {
35 35
 function mongo/drop-db {
36 36
     DB_NAME=$1
37 37
 
38
-    echo -e "Dropping db [${DB_NAME}]..."
38
+    echo -e "Dropping database [${DB_NAME}]..."
39 39
 
40 40
     if [[ $(mongo/db-exists? ${DB_NAME}) -lt 0 ]]; then
41
-        echo -e "${DB_NAME} does not exist, no need to drop."
41
+        echo -e "Database [${DB_NAME}] does not exist, no need to drop."
42 42
     else
43 43
         mongo/eval ${DB_NAME} "db.dropDatabase()"
44 44
     fi
@@ -46,10 +46,10 @@ function mongo/drop-db {
46 46
 
47 47
 function mongo/import {
48 48
     DB_NAME=$1
49
-    IMPORT_FILE=$2
50
-    echo "Importing to db [${DB_NAME}] from file [${IMPORT_FILE}]..."
51
-# mongoimport --host ${MONGO_HOST} : ${MONGO_PORT} -d ${DECODE_APP_DB_NAME} -c users --jsonArray --file ${SCRIPT_HOME}/../sample-data/users.json
52
-   # mongoimport --host ${MONGO_HOST} : ${MONGO_PORT} -d ${DECODE_APP_DB_NAME} -c petitions --jsonArray --file ${SCRIPT_HOME}/../sample-data/petitions.json
49
+    COLLECTION_NAME=$2
50
+    IMPORT_FILE=$3
51
+    echo "Importing to db [${DB_NAME}:${COLLECTION_NAME}] from file [${IMPORT_FILE}]..."
52
+    mongoimport --host=${MONGO_HOST} --port=${MONGO_PORT} --db=${DB_NAME} --collection=${COLLECTION_NAME} --jsonArray --file ${SCRIPT_HOME}/../sample-data/users.json
53 53
 
54 54
 
55 55