forked from neelabalan/mongodb-sample-dataset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·87 lines (80 loc) · 2.58 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
function import_collection {
local collections=("$@")
# cd "$dir"
echo "$LOGNAME"
for ((i = 0; i < ${#collections[@]}; i++)); do
# echo "${json_files[$i]}"
collection="${collections[$i]}"
json_file="${json_files[$i]}.json"
docker cp "$dir/$json_file" mongodb:"/$LOGNAME/"
docker exec -it mongodb mongoimport --host localhost --port 27017 --db vinay --collection "$collection" --file "/$LOGNAME/$json_file" --drop
if [ $? -eq 0 ]; then
echo "Import successful for collection '$collection'."
docker exec -it mongodb rm -rf "/$LOGNAME/$json_file"
else
echo "Error importing data into collection '$collection'."
fi
done
}
echo "Hey Hi $LOGNAME, do you want to import a MongoDB collection?"
echo "sample_analyticsmongodata: Enter 1"
echo "sample_geospatialmongodata: Enter 2"
echo "sample_mflixmongodata: Enter 3"
echo "exit: Enter 4"
while true; do
read -rp "Enter your choice: " action
case "$action" in
1)
# List of collection as well JSON files
collections=(
accounts
customers
transactions
)
json_files=(
accounts
customers
transactions
)
dir="/workspaces/mongodb-sample-dataset/sample_analytics"
import_collection "${collections[@]}"
break
;;
2)
# List of collection names and corresponding JSON files
collections=(
shipwrecks
)
json_files=(
shipwrecks
)
dir="/workspaces/mongodb-sample-dataset/sample_geospatial"
import_collection "${collections[@]}"
break
;;
3)
# List of collection names and corresponding JSON files
collections=(
comments
movies
sessions
)
json_files=(
comments
movies
sessions
)
dir="/workspaces/mongodb-sample-dataset/sample_mflix"
import_collection "${collections[@]}"
break
;;
4)
break
;;
*)
echo "Hi $LOGNAME You entered $action. Wrong input. Please enter 1, 2, or 3 || 4."
;;
esac
done
# docker cp "/workspaces/mongodb-sample-dataset/sample_geospatial/shipwrecks.json" mongodb:/vinay/