Skip to content

GeraAnggaraPutra/go-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go MongoDB

Local Development

How to Run

  1. Copy the .env.example file to .env:

    cp .env.example .env
  2. Configure your environment variables in .env:

    MONGODB_URI=mongodb://localhost:37017
    DATABASE_NAME=db-name
    
  3. Install Go dependencies:

    go mod tidy
  4. Run the app in development mode:

    go run main.go

Setup MongoDB Replica Set with Docker

  1. Start MongoDB containers:

    docker compose up -d --build
  2. Initialize the Replica Set:

    docker exec -it mongo1 mongosh
  3. 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" }
      ]
    })
  4. Check the replica set status:

    rs.status()

    Ensure there is a PRIMARY and two SECONDARY.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages