Vlad
Vlad

Reputation: 115

System.TimeoutException: A timeout occurred after 30000ms MongoDb

I am trying to compose my application (asp net core web api and mongodb) , but encountered error while trying to connect to db:

System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }", EndPoint: "Unspecified/localhost:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.

My appsettings.json:

{
  "DatabaseSettings": {
    "ConnectionString": "mongodb://localhost:27017",
    "DatabaseName": "CatalogDb",
    "CollectionName": "Products"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

docker-compose.override: version: '3.4'

services:
  catalogdb:
    container_name: catalogdb
    restart: always
    ports:
        - "27017:27017"
    volumes:
        - mongo_data:/data/db

  eshop.catalog.api:
    container_name: catalog.api
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - "DatabaseSettings:ConnectionString=mongodb://catalogdb:27017"
    depends_on:
      - catalogdb
    ports:
      - "8000:80"

docker-compose:

version: '3.4'

services:
  catalogdb:
    image: mongo

  eshop.catalog.api:
    image: ${DOCKER_REGISTRY-}eshopcatalogapi
    build:
      context: .
      dockerfile: EShop.Catalog.API/Dockerfile

volumes:
  mongo_data:

Upvotes: 2

Views: 1096

Answers (1)

Vlad
Vlad

Reputation: 115

Solved. I have change compose command on docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d and it works now

Upvotes: 2

Related Questions