Portabase Logo
Portabase AgentDatabases

MongoDB

Configuration for MongoDB.

The agent will use mongodump to perform backups and mongorestore to restore backups.

Configuration with Auth

{
  "name": "my-mongo-auth",
  "type": "mongodb",
  "host": "db-mongodb-auth",
  "port": 27017,
  "username": "username",
  "password": "password",
  "database": "testdbauth",
  "generated_id": "..."
}

Configuration without Authentication

{
  "name": "my-mongo",
  "type": "mongodb",
  "host": "db-mongodb",
  "port": 27017,
  "username": "",
  "password": "",
  "database": "testdb",
  "generated_id": "..."
}

Docker Compose Example

Example with a MongoDB image.

docker-compose.yml
services:
    db-mongodb-auth:
        container_name: db-mongodb-auth
        image: mongo:latest
        ports:
          - "27082:27017"
        environment:
          MONGO_INITDB_ROOT_USERNAME: root
          MONGO_INITDB_ROOT_PASSWORD: rootpassword
          MONGO_INITDB_DATABASE: testdbauth
        command: mongod --auth
        networks:
          - portabase
        volumes:
          - mongodb-data-auth:/data/db
        healthcheck:
          test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
          interval: 5s
          timeout: 5s
          retries: 10

    db-mongodb:
        container_name: db-mongodb
        image: mongo:latest
        ports:
          - "27083:27017"
        volumes:
          - mongodb-data:/data/db
        healthcheck:
          test: [ "CMD", "mongosh", "--eval", "db.adminCommand('ping')" ]
          interval: 5s
          timeout: 5s
          retries: 10
        environment:
          MONGO_INITDB_DATABASE: testdb
        networks:
          - portabase

    agent:
        image: portabase/agent:latest
        # ... agent configuration ...
        depends_on:
          - db-mongodb
          - db-mongodb-auth
        networks:
          - portabase

networks:
  portabase:
    external: true

volumes:
  mongodb-data:
  mongodb-data-auth:

If you use localhost as the host (because the agent is on the host machine and not in Docker, or via host-gateway), ensure your database is listening on all interfaces (0.0.0.0) or is accessible from the agent.

On this page