Objective
The common MongoDB deployment has a master, a standby, the program to connect MongoDB requires the address of the primary server and port, when the cluster deployment will have multiple server addresses need to connect, the MongoDB C # API can support simultaneous connection to multiple servers.
Single Station
mongoclient mc = new Mongoclient ("mongodb://oec2003:20720");
Mongoserver ms = MC. Getserver ();
Mongodatabase MD = Ms. Getdatabase ("dbname");
Cluster
list<mongoserveraddress> list = new list<mongoserveraddress> ();
List. ADD (New Mongoserveraddress ("192.168.16.207", 40000));
List. ADD (New Mongoserveraddress ("192.168.16.208", 40000));
List. ADD (New Mongoserveraddress ("192.168.16.209", 40000));
Mongoclientsettings MCS = new Mongoclientsettings ();
MCs. Servers = list;
mongoclient mc = new Mongoclient (MCS);
Mongoserver ms = MC. Getserver ();
Mongodatabase MD = Ms. Getdatabase ("dbname");