.net,个人封装MONGODDB的操作。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Driver; namespace CDPWIB.DAL
{
public class MongoConnectionFactory
{
//private static readonly string _connectionString = "mongodb://username:pwd@localhost:27000";
private static readonly string _connectionString = System.Configuration.ConfigurationSettings.AppSettings["entmongoconectionstring"]; //{ConnectionMode=Automatic;ConnectTimeout=00:00:30;Credentials={{DBNAME@USERNAME}};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 = 1000,
// SocketTimeout = new TimeSpan(0, 2, 0),
// WaitQueueTimeout = new TimeSpan(0, 0, 30), // //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, 30),
//}; public static MongoClientSettings clintser = new MongoClientSettings
{
Credentials = new List<MongoCredential>
{
//MongoCredential.CreateMongoCRCredential("usename", "db", "pwd")
},
MaxConnectionLifeTime = new TimeSpan(, , ),
MaxConnectionIdleTime = new TimeSpan(, , ),
MinConnectionPoolSize = ,
MaxConnectionPoolSize = ,
SocketTimeout = new TimeSpan(, , ),
WaitQueueTimeout = new TimeSpan(, , ), //Server = new MongoServerAddress("10.10.10.252", 27000),
Server = new MongoServerAddress("127.0.0.1", ),
//WaitQueueTimeout = new TimeSpan(0, 2, 0),
//
ConnectTimeout = new TimeSpan(, , ),
};
private static MongoClient mongoClient = new MongoClient(clintser); private static MongoServer mongoServer = mongoClient.GetServer(); public static MongoClient GetMongoClient()
{
return mongoClient;
} public static MongoServer 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); return mongoServer;
} public static MongoDatabase GetMongoDataBase(string dbname)
{ return GetMongoServer().GetDatabase(dbname);
} public static MongoCollection<T> GetMongoCollction<T>(MongoDatabase database, string collectionname)
{ return database.GetCollection<T>(collectionname);
}
public static MongoCollection<T> GetMongoCollction<T>(string databasename, string collectionname)
{
MongoDatabase database = GetMongoDataBase(databasename);
return database.GetCollection<T>(collectionname);
} public static MongoCollection<T> GetMongoCollction<T>(string databasename)
{
MongoDatabase database = GetMongoDataBase(databasename);
return database.GetCollection<T>(typeof(T).Name);
} public static MongoCollection GetMongoCollction(string databasename, string collectionname)
{
MongoDatabase database = GetMongoDataBase(databasename);
return database.GetCollection(collectionname);
} public static MongoCollection<T> GetMongoCollction<T>(MongoDatabase database, Type type)
{
return database.GetCollection<T>(type.Name);
}
public static MongoCollection<T> GetMongoCollction<T>(string databasename, Type type)
{
MongoDatabase database = mongoServer.GetDatabase(databasename);
return database.GetCollection<T>(type.Name);
} }
}

mongoDB连接信息及生成对应的collection生成代码的更多相关文章

  1. MongoDB警告信息

    更多内容推荐微信公众号,欢迎关注: MongoDB警告信息: 1. WARNING: Using the XFS filesystem is strongly recommended with the ...

  2. PHP - MongoDB连接攻略

    http://blog.163.com/lgh_2002/blog/static/44017526201261111044608/ 使用PHP的Mongo扩展连接MongoDB.通过new Mongo ...

  3. MongoDB 连接

    启动 MongoDB服务 在前面的教程中,我们已经讨论了如何启动MongoDB服务,你只需要在MongoDB安装目录的bin目录下执行'mongod'即可. 执行启动操作后,mongodb在输出一些必 ...

  4. MongoDB学习笔记——MongoDB 连接配置

    MongoDB连接标准格式: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[dat ...

  5. 查看Oracle数据库某用户的连接信息

    执行以下语句可查出用户TJAMIS_LXF连接信息: select schemaname, osuser, process, machine, port, terminal, program from ...

  6. cat .git/config查看远端服务器信息(git的配置信息:远端服务器连接信息)

    本地git库中,查找其连接的远端服务器信息: 每个git库都会有一个配置信息文件.git/config. cat .git/config,可以看到信息如下: [core]         reposi ...

  7. cdnbest如何查看节点和站点的流量,负载和连接信息

    1. 通过查看top信息,查看该区域下所有节点和有访问量的站点的负载情况 点节点列表==>top图标 2. 查看单台节点的负载和连接信息 点节点列表==>管理 点击下图中三个红框可以查看单 ...

  8. [Oracle]如何获得出现故障时,客户端的详细连接信息

    [Oracle]如何获得出现故障时,客户端的详细连接信息 客户坚持说 只是在 每天早上5点才运行下面的语句: select / * + FULL (TAB001_TT01) * / 'TAB001_T ...

  9. AIX 5335端口IBM WebSphere应用服务器关闭连接信息泄露漏洞的修复

    今天按要求协助进行漏洞修复,有个“IBM WebSphere应用服务器关闭连接信息泄露漏洞”,一直没太搞清是不是没打补丁引起的问题. 感觉同样的安装有的报这漏洞有的不报,而报的有的是应用端口,有时是控 ...

随机推荐

  1. 邮件发送,无尽的501错误。TCP发送邮件解决方案

    先贴上错误信息,便于搜索引擎采集,也送给遇到此问题的技术朋友们. smtp 501 Syntax error (no parameters allowed) (#5.5.4) 背景描述: 使用TCP发 ...

  2. Android自定义的弹窗

    package com.microduino.qoobot.view; import android.app.Activity; import android.app.Dialog; import a ...

  3. android implementation 依赖第三方库

    依赖第三方库

  4. Pmw大控件

    Python大控件——Pmw——是合成的控件,以Tkinter控件为基类,是完全在Python内写的.它们可以很方便地增加功能性的应用,而不必写一堆代码.特别是,组合框和内部确认计划的输入字段放在一起 ...

  5. java 中static关键字注意事项

    1.内存中存放的位置:(static修饰的方法和属性保存在方法区中,但是方法区也是堆的一部分) 内存的分区 2.什么样的属性可以定义为静态数据 例如: class person{ public Str ...

  6. Python笔记_第四篇_高阶编程_GUI编程之Tkinter_4.布局

    1. 绝对布局: 图示: 实例: import tkinter from tkinter import ttk # 创建主窗口__编程头部 win = tkinter.Tk() # 设置标题 win. ...

  7. Prometheus监控系统之入门篇(一)续

    在上篇Prometheus监控系统之入门篇(一)中我们讲解了Prometheus的基本架构和工作流程, 并从0到1搭建了Prometheus服务,pushgateway以及告警系统. 本篇我们主要介绍 ...

  8. apache 伪静态配置 .htaccess

    htaccess语法教程apache服务器伪静态规则教程 虽然网上有很多教程,不过发现大部分都是抄袭一个人的,一点都不全,所以我想写一个简单的易于理解的教程,我学习.htaccess是从目录保护开始的 ...

  9. jupyter notebook的扩展插件

    具体安装使用,请参考 https://github.com/ipython-contrib/IPython-notebook-extensions

  10. drf中的请求模块和渲染模块

    请求模块:request对象 APIView request.py # 在rest_framework.request.Request实例化方法中 self._request = request 将原 ...