version: '3.8'
services:
  # Config Server Replica Set
  config1:
    image: mongo
    container_name: config1
    command: ["mongod", "--configsvr", "--replSet", "ra_mongo_config", "--port", "27019"]
    ports:
      - "27019:27019"
    volumes:
      - ./config1_data:/data/db

  config2:
    image: mongo
    container_name: config2
    command: ["mongod", "--configsvr", "--replSet", "ra_mongo_config", "--port", "27019"]
    volumes:
      - ./config2_data:/data/db

  config3:
    image: mongo
    container_name: config3
    command: ["mongod", "--configsvr", "--replSet", "ra_mongo_config", "--port", "27019"]
    volumes:
      - ./config3_data:/data/db

  # Shard 1 Replica Set
  shard1:
    image: mongo
    container_name: shard1
    command: ["mongod", "--shardsvr", "--replSet", "ra_mongo_shard1", "--port", "27018"]
    ports:
      - "27018:27018"
    volumes:
      - ./shard1_data:/data/db

  # Shard 2 Replica Set
  shard2:
    image: mongo
    container_name: shard2
    command: ["mongod", "--shardsvr", "--replSet", "ra_mongo_shard2", "--port", "27018"]
    ports:
      - "27021:27018"  # Changed host port to 27021
    volumes:
      - ./shard2_data:/data/db

  # Mongos Router
  mongos:
    image: mongo
    container_name: mongos
    command: ["mongos", "--configdb", "ra_mongo_config/config1:27019,config2:27019,config3:27019"]
    ports:
      - "27020:27017"  # Expose mongos on port 27020
    depends_on:
      - config1
      - config2
      - config3
