Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
Is there a limit to set minPoolSize for Mongodb?

I'm trying to configure a pool connections to my Go program with mongodb, where I set minPoolSize to 20 connections using mongodb go driver. Something like that:

cli, err := mongo.Connect(ctx, options.Client().ApplyURI(uri).SetMinPoolSize(20).SetMaxConnIdleTime(time.Second*5))

I did a test where my program reached 100 connections allowed. After 5 seconds, the number of connections dropped to 10. But it should have kept 20 connections. If I set minPoolSize to 5, it works ok.

Is 10 connections a limit to MinPoolSize for mongodb? How can I change it to keep 20 connections?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You set the max connection idle time to 5 seconds. Quoting from ClientOptions.SetMaxConnIdleTime():

SetMaxConnIdleTime specifies the maximum amount of time that a connection will remain idle in a connection pool before it is removed from the pool and closed. This can also be set through the "maxIdleTimeMS" URI option (e.g. "maxIdleTimeMS=10000"). The default is 0, meaning a connection can remain unused indefinitely.

The 5 seconds you set means that if a connection is in the pool and is not used for 5 seconds, it can be removed from the pool.

And you said you waited 5 seconds, and you experienced that connections in the pool were closed. This is the intended / allowed behavior.

If you want the connections to stay alive indefinitely, don't set the max connection idle time, or set 0 explicitly:

cli, err := mongo.Connect(ctx, options.Client()
    .ApplyURI(uri)
    .SetMinPoolSize(20)
    .SetMaxConnIdleTime(0))

You could ask what's the point of setting min pool size if connections can still be dropped from it. Yes, that's true, but only after the idle time has expired. The pool size may peak above the allowed minimum, e.g. if you set 20 as the minimum, and there's a need for a 100 connections, then 100 connections may be created. If all those 100 connections become idle, you can be sure at least 20 will be kept alive, for the idle time duration. If min pool size would be set to 10, you would have only guarantee for 10 being kept alive.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda