-
Copy the
.env.examplefile to.env:cp .env.example .env
-
Configure your environment variables in
.env:MONGODB_URI=mongodb://localhost:37017 DATABASE_NAME=db-name -
Install Go dependencies:
go mod tidy
-
Run the app in development mode:
go run main.go
-
Start MongoDB containers:
docker compose up -d --build
-
Initialize the Replica Set:
docker exec -it mongo1 mongosh -
Inside the Mongo shell, run:
rs.initiate({ _id: "my-mongo-set", members: [ { _id: 0, host: "mongo1:27017" }, { _id: 1, host: "mongo2:27017" }, { _id: 2, host: "mongo3:27017" } ] })
-
Check the replica set status:
rs.status()
Ensure there is a PRIMARY and two SECONDARY.