Skip to content

Commit bb70f4e

Browse files
committed
mongo connexion fix
1 parent a1f1376 commit bb70f4e

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

mern/backend/db/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MongoClient, ServerApiVersion } from "mongodb";
22

3-
const URI = "mongodb://mongodb:27017";
3+
const URI = process.env.MONGODB_URI || "mongodb://mongo:27017";
44
const client = new MongoClient(URI, {
55
serverApi: {
66
version: ServerApiVersion.v1,

mern/docker-compose.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
services:
2+
frontend:
3+
build: ./frontend
4+
ports:
5+
- "5173:5173"
6+
networks:
7+
- mern
8+
backend:
9+
build: ./backend
10+
ports:
11+
- "5050:5050"
12+
networks:
13+
- mern
14+
environment:
15+
- MONGODB_URI=mongodb://mongo:27017
16+
depends_on:
17+
mongo:
18+
condition: service_healthy
19+
mongo:
20+
image: mongo:latest
21+
ports:
22+
- "27017:27017"
23+
networks:
24+
- mern
25+
volumes:
26+
- mongo-data:/data/db
27+
healthcheck:
28+
test: ["CMD", "mongosh", "--eval", "db.runCommand({ ping: 1 })"]
29+
interval: 10s
30+
timeout: 5s
31+
retries: 5
32+
33+
networks:
34+
mern:
35+
driver: bridge
36+
37+
volumes:
38+
mongo-data:
39+
driver: local

0 commit comments

Comments
 (0)