MongoDB connection information and generate the corresponding collection generated code

Source: Internet
Author: User
Tags mongoclient

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.