2

I'm just looking for a way to initialize a MongoClient using MongoClientSettings with a provided connection string.

Can not find any example of this on the project website. These are all their examples:

// To directly connect to a single MongoDB server
// (this will not auto-discover the primary even if it's a member of a replica set)
var client = new MongoClient();

// or use a connection string
var client = new MongoClient("mongodb://localhost:27017");

// or, to connect to a replica set, with auto-discovery of the primary, supply a seed list of members
var client = new MongoClient("mongodb://localhost:27017,localhost:27018,localhost:27019");

1 Answer 1

5

This way you can do it:

MongoClientSettings settings = MongoClientSettings.FromConnectionString("ConnectionString");
// change some fields based on your needs
settings.WaitQueueTimeout = TimeSpan.FromMinutes(1);
settings.MinConnectionPoolSize = 100;
settings.MaxConnectionPoolSize = 500;

And create the MongoClient using this command:

var client = new MongoClient(settings);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.