Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=vinay
13 changes: 10 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
version: '3.9'
version: '3.8'

services:
mongodb:
image: mongo:latest
container_name: mongodb
restart: always
environment:
env_file: ./env
ports:
- 27017:27017
- "27017:27017"
volumes:
- ~/mongodb/mongo:/data/db
- mongodb_data:/data/db

volumes:
mongodb_data:
8 changes: 8 additions & 0 deletions playground-3.mongodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@




use("vinay");
db.accounts.find(
{}
);
1 change: 1 addition & 0 deletions sample_analytics/accounts.json
Original file line number Diff line number Diff line change
Expand Up @@ -1744,3 +1744,4 @@
{"_id":{"$oid":"5ca4bbc7a2dd94ee58162a5e"},"account_id":{"$numberInt":"684319"},"limit":{"$numberInt":"10000"},"products":["InvestmentFund","InvestmentStock"]}
{"_id":{"$oid":"5ca4bbc7a2dd94ee58162a5f"},"account_id":{"$numberInt":"351063"},"limit":{"$numberInt":"10000"},"products":["InvestmentStock"]}
{"_id":{"$oid":"5ca4bbc7a2dd94ee58162a60"},"account_id":{"$numberInt":"291224"},"limit":{"$numberInt":"10000"},"products":["Commodity","InvestmentStock"]}
{"_id":{"$oid":"5ca4bbc7a2dd94ee58162a60"},"account_id":{"$numberInt":"291224"},"limit":{"$numberInt":"10000"},"products":["Commodity","InvestmentStock"]}
6 changes: 6 additions & 0 deletions sample_analytics/customers.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,9 @@
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5c"},"username":"smcintyre","name":"Christopher Lawrence","address":"00881 West Flat\nNorth Emily, IL 32130","birthdate":{"$date":{"$numberLong":"857586057000"}},"email":"vkeith@yahoo.com","accounts":[{"$numberInt":"551774"},{"$numberInt":"264502"},{"$numberInt":"599670"},{"$numberInt":"193228"},{"$numberInt":"397774"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5d"},"username":"qknight","name":"Gabriel Romero","address":"79375 David Neck\nWest Matthewton, NJ 92863","birthdate":{"$date":{"$numberLong":"42240010000"}},"email":"erica98@gmail.com","accounts":[{"$numberInt":"568852"},{"$numberInt":"351063"},{"$numberInt":"635650"},{"$numberInt":"229182"},{"$numberInt":"732327"},{"$numberInt":"89698"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5e"},"username":"ecasey","name":"Brandon Contreras","address":"6942 Connie Skyway\nPatrickville, WA 16551","birthdate":{"$date":{"$numberLong":"120268330000"}},"email":"amber97@hotmail.com","accounts":[{"$numberInt":"896364"},{"$numberInt":"450464"}],"tier_and_details":{"f4cebafe5530421b991303dff297643d":{"tier":"Platinum","benefits":["shopping discounts"],"active":true,"id":"f4cebafe5530421b991303dff297643d"}}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c59"},"username":"davidsonomar","name":"Linda Stephens","address":"399 Fuentes Roads\nJoshuaborough, CO 64522","birthdate":{"$date":{"$numberLong":"528484365000"}},"email":"cynthia31@hotmail.com","accounts":[{"$numberInt":"669413"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5a"},"username":"amandawilliams","name":"Brandy Huang","address":"9505 Melissa Streets\nSouth Frankville, NJ 91189","birthdate":{"$date":{"$numberLong":"180627718000"}},"email":"scottjonathan@yahoo.com","accounts":[{"$numberInt":"650729"},{"$numberInt":"991663"},{"$numberInt":"144876"},{"$numberInt":"912504"},{"$numberInt":"88163"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5b"},"username":"stricklandjeffery","name":"Xavier Myers","address":"499 Jonathan Streets Apt. 890\nEast Ashley, MD 76825","birthdate":{"$date":{"$numberLong":"562100715000"}},"email":"fredsmith@yahoo.com","accounts":[{"$numberInt":"285957"},{"$numberInt":"875868"},{"$numberInt":"138703"},{"$numberInt":"122908"},{"$numberInt":"370468"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5c"},"username":"smcintyre","name":"Christopher Lawrence","address":"00881 West Flat\nNorth Emily, IL 32130","birthdate":{"$date":{"$numberLong":"857586057000"}},"email":"vkeith@yahoo.com","accounts":[{"$numberInt":"551774"},{"$numberInt":"264502"},{"$numberInt":"599670"},{"$numberInt":"193228"},{"$numberInt":"397774"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5d"},"username":"qknight","name":"Gabriel Romero","address":"79375 David Neck\nWest Matthewton, NJ 92863","birthdate":{"$date":{"$numberLong":"42240010000"}},"email":"erica98@gmail.com","accounts":[{"$numberInt":"568852"},{"$numberInt":"351063"},{"$numberInt":"635650"},{"$numberInt":"229182"},{"$numberInt":"732327"},{"$numberInt":"89698"}],"tier_and_details":{}}
{"_id":{"$oid":"5ca4bbcea2dd94ee58162c5e"},"username":"ecasey","name":"Brandon Contreras","address":"6942 Connie Skyway\nPatrickville, WA 16551","birthdate":{"$date":{"$numberLong":"120268330000"}},"email":"amber97@hotmail.com","accounts":[{"$numberInt":"896364"},{"$numberInt":"450464"}],"tier_and_details":{"f4cebafe5530421b991303dff297643d":{"tier":"Platinum","benefits":["shopping discounts"],"active":true,"id":"f4cebafe5530421b991303dff297643d"}}}
25 changes: 0 additions & 25 deletions script.sh

This file was deleted.

97 changes: 97 additions & 0 deletions work/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

function import_collection {
local collections=("$@")
# cd "$dir"
# echo "$LOGNAME"
> /workspaces/mongodb-sample-dataset/work/mongo.log
docker exec -it mongodb mkdir -p vinay
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

docker cp "$dir/$json_file" mongodb:"/vinay/" >> /workspaces/mongodb-sample-dataset/work/mongo.log 2>&1
docker exec -it mongodb mongoimport --host localhost --port 27017 --db vinay --collection "$collection" --file "/vinay/$json_file" --drop >> /workspaces/mongodb-sample-dataset/work/mongo.log 2>&1
echo $import_log >> /workspaces/mongodb-sample-dataset/work/mongo.log
if [ $? -eq 0 ]; then
echo "Import successful for collection '$collection'."
# docker exec -it mongodb rm -rf "/$LOGNAME/$json_file"
# docker exec -it mongodb rm -rf "/vinay/$json_file"
else
echo "Error importing data into collection '$collection'."
fi
sleep 1
done
docker exec -it mongodb rm -rf /vinay/
}



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
go build /workspaces/mongodb-sample-dataset/work/main.go
./main

# docker cp "/workspaces/mongodb-sample-dataset/sample_geospatial/shipwrecks.json" mongodb:/vinay/
Binary file added work/main
Binary file not shown.
Loading