M220N Connection Pooling

I am not trying to get all the answers… But when I read the link provided for information on the connection string, it takes me to the MongoDB documentation on the “string” When you scroll down to the applicable section (Connection Pool), the section is in the options portion of the page… This portion stipulates that the option is set with an = sign… I don’t think this is accurate in the Visual Studio environment.

Also… the documentation contains no reference on how to use this in a appsettings.json setting. LOL

I assume I want to update the “ConnectionStrings” setting in the appsettings.json file, but I cannot get any reference on how this is done. I have searched the Microsoft documentation and all I can find is what the connection pool does and how to modify it. But there is no reference on how this is done.

Looking at the appsettings.json file I am assuming that it is a key : value pairing. this would lead me to use
“ConnectionStrings”: {“maxPoolSize”: “50”},

This doesn’t pass… If I use an = sign I get a syntax error.
Is there any documentation on how to properly write a appsettings.json file?

Also… No matter what you do to the file… (using the above condition) the test TestVerifyConfigSettings always passes… (at lease it did for me) but the test Connection Pool fails…

This is the file I am looking at to edit.

{
  "AllowedHosts": "*",
  "JwtAuthentication": {
    "SecurityKey": "ouNtF8Xds1jE55/d+iVZ99u0f2U6lQ+AHdiPFwjVW3o=",
    "ValidAudience": "https://localhost:5000/",
    "ValidIssuer": "https://localhost:5000/"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "maxPoolSize" : "50"
  },
  "MongoUri": "mongodb+srv://M220student:m220password@mflix.fn5qt.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
}

The part I added was the “ConnectionStrings” portion… It is the only reference I can find that has the potential to change the connection pool that I know of.

Hi @David_Thompson, you are on the correct file, but you need to update your connection string, learn more about that here in the connection-string docs.

I hope it helps. In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Thanks!!! I was under the impression that it was a global variable that I needed to set… Once you responded, I saw where I was going wrong.

That brings me to my next question regarding Connection Pools…
I understand the concept, I am now wondering the best way to apply the concept.

The way I understand the appsettings.json file is that every time the application is launched(Connection request to the home page), the “MongoUri” in the appsettings.json file is executed. For example, Client A types in www.ABC.com in his browser, That query for ABC.com goes the the Azure server where ABC.com’s application sits and it launches an it starts the execution of startup.cs… Am I right so far?

If this is correct, startup.cs evaluates the appsettings.json file and executes the connection string “MongoUri”. This is where the connection pool is established…

The question I have is that it seems to me that every instance of the startup.cs would launch another instance of the connection pool… Client A would have his own connection, Client B would have another… Each having their respective “pools”.

My original understanding of the pool (also reinforced from the video showing multiple clients connecting using the “pool” of connections) is that the individual clients (A & B) would “share” the connection pool.

But if each launches another instance, they would each have their own pool to draw from. The pool would only benefit them for multiple connections from within the same instance. This seems to be a waste of the pool feature.

Is there a way to set the global variable? To in fact limit the pool size for client connection requests?

I feel like I am not conveying my question real well. Maybe I should state it another way… When is appsettings.json executed? Is it executed when the application is deployed on the server and waiting for Client A and Client B, or is it executed when the client “hits” the application from the browser(requests a connection to the home page)?

Hi @David_Thompson.

appsettings.json never gets “executed” it just works as a data/value provider, so whenever you run the server the MongoClient gets instantiated and for that, the driver needs the connection-string, and at that point of time the server reads the appsettings.json file and provides it to the driver to instantiate. So it is independent of all the client-server side communications, but it does depend on the (re)start of the server.

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.