title: The wait queue for acquiring a connection to server ******* is full. [MongoDB]
body: <p>I'm having this error... I'm using ASP.NET Core with the last version of driver C#. </p>
  
  <blockquote>
    <p>The wait queue for acquiring a connection to server [server:port] is
    full.</p>
  </blockquote>
  
  <p><strong>Failed Method:</strong></p>
  
  <blockquote>
    <p>MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection</p>
  </blockquote>
  
  <p><strong>Call Stack:</strong></p>
  
  <pre><code>MongoDB.Driver.MongoWaitQueueFullException
  MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection
  MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+&lt;AcquireConnectionAsync&gt;d__35.MoveNext
  [external code]
  MongoDB.Driver.Core.Servers.ClusterableServer+&lt;GetChannelAsync&gt;d__40.MoveNext
  [external code]
  MongoDB.Driver.Core.Operations.FindOperation`1+&lt;ExecuteAsync&gt;d__107.MoveNext
  [external code]
  MongoDB.Driver.OperationExecutor+&lt;ExecuteReadOperationAsync&gt;d__1`1.MoveNext
  [external code]
  MongoDB.Driver.MongoCollectionImpl`1+&lt;ExecuteReadOperationAsync&gt;d__59`1.MoveNext
  [external code]
  MongoDB.Driver.IAsyncCursorSourceExtensions+&lt;FirstOrDefaultAsync&gt;d__5`1.MoveNext
  [external code]
  Microsoft.ApplicationInsights.AspNet.ExceptionTrackingMiddleware+&lt;Invoke&gt;d__4.MoveNext
  </code></pre>
  
  <p>I have a Singleton DB Context.</p>
  
  <p><strong>Example API Controller:</strong></p>
  
  <pre><code>[HttpPut]
          [Route("UpdatePosition")]
          public async Task&lt;IActionResult&gt; 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);
          }
  </code></pre>
  
  <p><strong>Service method:</strong></p>
  
  <pre><code>public async Task&lt;string&gt; 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;
          }
  </code></pre>
  
  <p>The GetArea and Update method are from a Repository Pattern:</p>
  
  <p><strong>Update method:</strong></p>
  
  <pre><code>public virtual async Task&lt;T&gt; Update(T entity)
      {
          await _collection.ReplaceOneAsync(x =&gt; entity.Id.Equals(x.Id), entity, new UpdateOptions { IsUpsert = true });
          return entity;
      }
  </code></pre>
  
  <p><strong>Get Area Method:</strong></p>
  
  <pre><code> private async Task&lt;Area&gt; GetArea(AreaDto dto)
          {
              var area = await _repositoryAreas.FirstOrDefaultAsync(t =&gt; t.Id == dto.Id);
  
              if (area == null)
                  return null;
  
  
              return area;
  
          }
  </code></pre>
  
  <p>I have many other methods using mongoDB, but this is an example... </p>
  
  <p><strong>Instance class IMongoDatabse:</strong></p>
  
  <pre><code>private static IMongoDatabase GetDatabaseFromUrl(MongoUrl url)
          {
              var client = new MongoClient(url);
              return client.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged
          }
  </code></pre>
  
  <p>Any ideas?</p>