我开发了以下示例应用程序。
private static string connectionString = "mongodb://db1.db.com:27017,db2.db.com:27017,db3.db.com:27017,db4.db.com:27017,db5.db.com:27017/myTestDB?replicaSet=rpl&retryWrites=true&serverSelectionTimeoutMS=5000";
private static IMongoClient _mongoClient = new MongoClient(connectionString);
private static IMongoDatabase _dataBase = _mongoClient.GetDatabase("myTestDB");
private static IMongoCollection<MyClass> _collection = _dataBase.GetCollection<MyClass>("myTestCollection");
static void Main(string[] args)
{
Console.WriteLine("Press Enter to start...");
Console.ReadLine();
var obj = new MyClass { Id = 1, Name = "MyData", Email="asd@asd.com" };
Console.WriteLine("Enter your email:");
var email= Console.ReadLine();
for (int i = 0; i < 1000000; i++)
{
var endpoint = GetUrl(url);
Console.Write(_dataBase.Client.Cluster.ClusterId.Value.ToString());
}
Console.ReadLine();
}
我想测试我的Replicaset。当主节点出现故障时,我该怎么做以自动更改主节点? 现在,当我停止我的主节点(以进行测试)时,需要重置我的应用程序。我需要自动执行此操作。