Sign inSign up

nesvet/mongo-rs

By nesvet

•Updated 8 months ago

MongoDB with replica set and healthcheck out of the box. Node.js, Mongoose, Docker Compose ready.

Image
Databases & storage
1

2.6K

nesvet/mongo-rs repository overview

⁠MongoDB with replica set

CI Docker Image

Your app needs a replica set — Node.js driver, Mongoose, Change Streams, transactions all require it. The official mongo image⁠ runs standalone; mongo-rs extends it with a replica set on first run. One container, no init scripts.

docker run -d -e MONGO_PASSWORD=secret nesvet/mongo-rs
⁠Docker Compose
docker compose up -d

Example with app service:

services:
  mongo:
    image: nesvet/mongo-rs
    environment:
      MONGO_PASSWORD: ${MONGO_PASSWORD:-secret}
    volumes:
      - mongo-data:/data/db
    restart: unless-stopped

  app:
    image: myapp:latest
    environment:
      MONGO_URI: mongodb://root:${MONGO_PASSWORD:-secret}@mongo:27017/?directConnection=true
    depends_on:
      mongo:
        condition: service_healthy

volumes:
  mongo-data:

⁠Features

  • Auto-init replica set — rs.initiate() on first run, no manual setup
  • Built-in healthcheck — 15s interval, ready for depends_on: condition: service_healthy
  • Env-based config — MONGO_RS, MONGO_USER, MONGO_PASSWORD, MONGO_AUTHDB
  • Secrets support — MONGO_PASSWORD_FILE for Docker secrets / Kubernetes
  • FCV auto-update — featureCompatibilityVersion aligned with MongoDB version

⁠Use cases

→ Local dev with Node.js / Mongoose
No more MongoServerSelectionError: connection refused. Your driver expects a replica set; mongo-rs provides one.

→ Docker Compose with depends_on
Healthcheck built in. depends_on works out of the box.

→ Same setup dev → prod
Single node locally, add nodes in production. Same connection string format, no code changes.

⁠Usage

VariableDefaultDescription
MONGO_RSrs0Replica set name
MONGO_AUTHDBadminAuthentication database
MONGO_USERrootAdmin username
MONGO_PASSWORDiddqdAdmin password
MONGO_PASSWORD_FILE—Path to file with password (Docker secrets)

Connection string (single-node, use directConnection=true): options⁠

mongodb://root:${MONGO_PASSWORD}@mongo:27017/?directConnection=true

⁠Production

  • Change default password — iddqd is for dev only

  • Use secrets — MONGO_PASSWORD_FILE with Docker secrets or an external secret manager:

    services:
      mongo:
        image: nesvet/mongo-rs
        environment:
          MONGO_PASSWORD_FILE: /run/secrets/mongo_password
        secrets:
          - mongo_password
        volumes:
          - mongo-data:/data/db
        restart: unless-stopped
    
    secrets:
      mongo_password:
        file: ./secrets/mongo_password.txt
    
    volumes:
      mongo-data:
    
  • See SECURITY.md⁠ for vulnerability reporting

⁠Testing

./test.sh

⁠Support this project

mongo-rs is free, open-source, and maintained by one developer.

If it saves you time or improves your MongoDB replica set setup:

  • ⭐ Star it — it helps discoverability
  • 💙 Support on Patreon⁠ — priority features & long-term maintenance

⁠Contributing

GitHub⁠ • See CONTRIBUTING.md⁠

⁠License

MIT⁠

Tag summary

Content type

Image

Digest

sha256:1bd9ec348…

Size

313.8 MB

Last updated

8 months ago

docker pull nesvet/mongo-rs