1

I am using the below code to connect mongo DB.

public static class MongoDBHandler
{
    static IMongoClient _client;
    static IMongoDatabase _database;
    static string MongoDBConnectionString;

    static IMongoClient mClientConnection()
    {
        MongoDBConnectionString = System.Configuration.ConfigurationManager.AppSettings["connectionString"];
        _client = new MongoClient(MongoDBConnectionString);
        return _client;
    }

    public static IMongoDatabase mDatabase()
    {
        try
        {
            if (_client == null)
            {
                _client = mClientConnection();
            }

            if (_database == null)
            {
                var mongoUrl = new MongoUrl(MongoDBConnectionString);
                _database = _client.GetDatabase(mongoUrl.DatabaseName);
            }
            return _database;
        }
        catch
        {
            throw;
        }
    }
}

I am using above class code like below:-

protected static IMongoDatabase _database;

public void GetData()
{
    _database = Assistant.MongoDBHandler.mDatabase();
    IMongoCollection<Models.RoomTypeMappingOnline> collection_rto = _database.GetCollection<Models.RoomTypeMappingOnline>("collection");
    //Rest of code
}

My code is working fine. I am able to get the data without any issues with less number of request.

But when I am getting more request, then I am getting the "The wait queue for acquiring a connection to server is full" error.

Below is my connection string:-

mongodb://admin:password@server:11111/databse?authSource=sa&appName=database&connectTimeoutMS=5000&minPoolSize=3000&retryWrites=true&waitQueueMultiple=15

Please suggest what changes I can made to my code so that it can work without error.

user2043071
  • 105
  • 1
  • 2
  • 15

1 Answers1

2

I just increase the minPoolSize=3000 to minPoolSize=5000 in mongo db connection. This will solve my issue.

Also please note if you increase the min pool size, then the mongo server CPU and memory utilization will also increase. So you need to monitor this before you increase the size.

user2043071
  • 105
  • 1
  • 2
  • 15