Skip to content

Commit

Permalink
[MongoDB] Fixes local Docker setup and load_data script (#13)
Browse files Browse the repository at this point in the history
* Update docker compose and use connection string

* correct os env name

* Add env connection string to docker compose
  • Loading branch information
tianjing-li authored Dec 12, 2023
1 parent 233e6c9 commit ee28963
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 4 additions & 5 deletions mongodb/dev/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

load_dotenv()

client = pymongo.MongoClient(
host=os.environ.get("MONGODB_HOST", "mongo"),
port=os.environ.get("MONGODB_PORT", 27017),
username=os.environ.get("MONGODB_ROOT_USERNAME", "root"),
password=os.environ.get("MONGODB_ROOT_PASSWORD", "example"),
connection_string = os.environ.get(
"MONGODB_CONNECTION_STRING", "mongodb://root:example@mongo:27017"
)

client = pymongo.MongoClient(connection_string)

fields = []

db = client.bbq
Expand Down
6 changes: 4 additions & 2 deletions mongodb/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: "1"
version: "3.8"
services:
mongo:
image: mongo:latest
container_name: mongo
restart: unless-stopped
restart: always
ports:
- 27017:27017
environment:
Expand All @@ -18,6 +18,8 @@ services:
container_name: data-loader
depends_on:
- mongo
environment:
MONGODB_CONNECTION_STRING: mongodb://root:example@mongo:27017
volumes:
- ./dev/bbq.csv:/bbq.csv
- ./dev/load_data.py:/load_data.py
Expand Down

0 comments on commit ee28963

Please sign in to comment.