0

我只是在寻找一种使用提供的连接字符串初始化MongoClientusing的方法。MongoClientSettings

在项目网站上找不到任何这样的例子。这些都是他们的例子:

// 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");
4

1 回答 1

0

这样你就可以做到这一点:

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

MongoClient使用以下命令创建:

var client = new MongoClient(settings);
于 2021-10-05T15:44:49.390 回答