获取与服务器*******的连接的等待队列已满。 [MongoDB的]

时间:2016-05-10 10:05:14

标签: mongodb mongodb-.net-driver mlab

我遇到了这个错误......我正在使用ASP.NET Core和最新版本的驱动程序C#。

  

获取与服务器[server:port]的连接的等待队列是   满。

方法失败:

  

MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool + AcquireConnectionHelper.CheckingOutConnection

致电堆栈:

MongoDB.Driver.MongoWaitQueueFullException
MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection
MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+<AcquireConnectionAsync>d__35.MoveNext
[external code]
MongoDB.Driver.Core.Servers.ClusterableServer+<GetChannelAsync>d__40.MoveNext
[external code]
MongoDB.Driver.Core.Operations.FindOperation`1+<ExecuteAsync>d__107.MoveNext
[external code]
MongoDB.Driver.OperationExecutor+<ExecuteReadOperationAsync>d__1`1.MoveNext
[external code]
MongoDB.Driver.MongoCollectionImpl`1+<ExecuteReadOperationAsync>d__59`1.MoveNext
[external code]
MongoDB.Driver.IAsyncCursorSourceExtensions+<FirstOrDefaultAsync>d__5`1.MoveNext
[external code]
Microsoft.ApplicationInsights.AspNet.ExceptionTrackingMiddleware+<Invoke>d__4.MoveNext

我有一个Singleton DB Context。

示例API控制器:

[HttpPut]
        [Route("UpdatePosition")]
        public async Task<IActionResult> UpdatePosition([FromBody]AreaDto dto)
        {
            var idUser = User.GetUserId();

            if (dto == null)
                return HttpBadRequest("Fail request");

            _service.IdUser = idUser;


            var item = await _service.UpdateAreaPosition(dto);

            if (item == null)
                return HttpBadRequest("Fail request");

            return Ok(item);
        }

服务方式:

public async Task<string> UpdateAreaPosition(AreaDto dto)
        {
            var area = await GetArea(dto);

            if (area == null || dto.Position?.PositionLeft == null || dto.Position.PositionTop == null) return null;

            area.Position.PositionLeft = dto.Position.PositionLeft;
            area.Position.PositionTop = dto.Position.PositionTop;
            await _repositoryAreas.Update(area);
            return area.Id;
        }

GetArea和Update方法来自存储库模式:

更新方法:

public virtual async Task<T> Update(T entity)
    {
        await _collection.ReplaceOneAsync(x => entity.Id.Equals(x.Id), entity, new UpdateOptions { IsUpsert = true });
        return entity;
    }

获取区域方法:

 private async Task<Area> GetArea(AreaDto dto)
        {
            var area = await _repositoryAreas.FirstOrDefaultAsync(t => t.Id == dto.Id);

            if (area == null)
                return null;


            return area;

        }

我有很多其他使用mongoDB的方法,但这是一个例子......

实例类IMongoDatabse:

private static IMongoDatabase GetDatabaseFromUrl(MongoUrl url)
        {
            var client = new MongoClient(url);
            return client.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged
        }

有什么想法吗?

0 个答案:

没有答案