usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingMongodb.driver;namespaceCdpwib. DAL { Public classMongoconnectionfactory {//private static readonly string _connectionstring = "MongoDB://username:[email protected]:27000 ";Private Static ReadOnly string_connectionstring = system.configuration.configurationsettings.appsettings["entmongoconectionstring"]; //{connectionmode=automatic; connecttimeout=00:00:30; Credentials={{[email protected]}}; Guidrepresentation=csharplegacy;ipv6=false; maxconnectionidletime=00:10:00; maxconnectionlifetime=00:30:00; maxconnectionpoolsize=100; minconnectionpoolsize=0; Readpreference=primary; Replicasetname=; secondaryacceptablelatency=00:00:00.0150000; servers=10.10.10.252:27000; sockettimeout=00:00:00; Ssl=false; Sslverifycertificate=true; waitqueuesize=500; Waitqueuetimeout=00:02:00writeconcern=w=1;} //Public static Mongoclientsettings clintser = new Mongoclientsettings//{ // //Credentials = new List<mongocredential>// //{ // //mongocredential.createmongocrcredential ("USERNAME", "DBNAME", "DB")// //}, //maxconnectionlifetime = new TimeSpan (0, 5, 0),//maxconnectionidletime = new TimeSpan (0, 2, 0),//minconnectionpoolsize = 0,//maxconnectionpoolsize = +,//sockettimeout = new TimeSpan (0, 2, 0),//waitqueuetimeout = new TimeSpan (0, 0,),// //Server = new Mongoserveraddress ("10.10.10.252", 27000),//Server = new Mongoserveraddress ("127.0.0.1", 27000),// //waitqueuetimeout = new TimeSpan (0, 2, 0),// // //connecttimeout = new TimeSpan (0, 0,),//}; Public StaticMongoclientsettings Clintser =Newmongoclientsettings {Credentials=NewList<mongocredential> { //mongocredential.createmongocrcredential ("Usename", "db", "pwd")}, Maxconnectionlifetime=NewTimeSpan (0,5,0), Maxconnectionidletime=NewTimeSpan (0,2,0), Minconnectionpoolsize=0, Maxconnectionpoolsize= +, Sockettimeout=NewTimeSpan (0,2,0), Waitqueuetimeout=NewTimeSpan (0,0, -), //Server = new Mongoserveraddress ("10.10.10.252", 27000),Server =NewMongoserveraddress ("127.0.0.1",27017), //waitqueuetimeout = new TimeSpan (0, 2, 0),//ConnectTimeout =NewTimeSpan (0,0, -), }; Private StaticMongoclient mongoclient =Newmongoclient (clintser);Private StaticMongoserver Mongoserver =mongoclient.getserver (); Public Staticmongoclient getmongoclient () {returnmongoclient;} Public Staticmongoserver Getmongoserver () {//var seting = mongoserver.settings;//seting. ConnectTimeout = new TimeSpan (0, 2, 0); //seting. minconnectionpoolsize = 100; //seting. maxconnectionpoolsize = 1000; //seting. Sockettimeout = new TimeSpan (0, 2, 0); //seting. Waitqueuetimeout = new TimeSpan (0, 2, 0); returnMongoserver;} Public StaticMongodatabase Getmongodatabase (stringdbname) { returnGetmongoserver (). Getdatabase (dbname); } Public StaticMongocollection<t> getmongocollction<t> (Mongodatabase database,stringCollectionName) { returnDatabase. Getcollection<t>(CollectionName);} Public StaticMongocollection<t> getmongocollction<t> (stringDatabaseNamestringCollectionName) {Mongodatabase Database=getmongodatabase (databasename);returnDatabase. Getcollection<t>(CollectionName);} Public StaticMongocollection<t> getmongocollction<t> (stringdatabasename) {Mongodatabase Database=getmongodatabase (databasename);returnDatabase. Getcollection<t> (typeof(T). Name); } Public StaticMongocollection Getmongocollction (stringDatabaseNamestringCollectionName) {Mongodatabase Database=getmongodatabase (databasename);returndatabase. GetCollection (CollectionName); } Public StaticMongocollection<t> getmongocollction<t>(mongodatabase database, type type) {returnDatabase. Getcollection<t>(type. Name); } Public StaticMongocollection<t> getmongocollction<t> (stringdatabasename, type type) {Mongodatabase Database=mongoserver.getdatabase (databasename);returnDatabase. Getcollection<t>(type. Name); } } }
MongoDB connection information and generate the corresponding collection generated code