mongoDB连接信息及生成对应的collection生成代码
.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生成代码的更多相关文章
- MongoDB警告信息
		更多内容推荐微信公众号,欢迎关注: MongoDB警告信息: 1. WARNING: Using the XFS filesystem is strongly recommended with the ... 
- PHP - MongoDB连接攻略
		http://blog.163.com/lgh_2002/blog/static/44017526201261111044608/ 使用PHP的Mongo扩展连接MongoDB.通过new Mongo ... 
- MongoDB 连接
		启动 MongoDB服务 在前面的教程中,我们已经讨论了如何启动MongoDB服务,你只需要在MongoDB安装目录的bin目录下执行'mongod'即可. 执行启动操作后,mongodb在输出一些必 ... 
- MongoDB学习笔记——MongoDB 连接配置
		MongoDB连接标准格式: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[dat ... 
- 查看Oracle数据库某用户的连接信息
		执行以下语句可查出用户TJAMIS_LXF连接信息: select schemaname, osuser, process, machine, port, terminal, program from ... 
- cat .git/config查看远端服务器信息(git的配置信息:远端服务器连接信息)
		本地git库中,查找其连接的远端服务器信息: 每个git库都会有一个配置信息文件.git/config. cat .git/config,可以看到信息如下: [core] reposi ... 
- cdnbest如何查看节点和站点的流量,负载和连接信息
		1. 通过查看top信息,查看该区域下所有节点和有访问量的站点的负载情况 点节点列表==>top图标 2. 查看单台节点的负载和连接信息 点节点列表==>管理 点击下图中三个红框可以查看单 ... 
- [Oracle]如何获得出现故障时,客户端的详细连接信息
		[Oracle]如何获得出现故障时,客户端的详细连接信息 客户坚持说 只是在 每天早上5点才运行下面的语句: select / * + FULL (TAB001_TT01) * / 'TAB001_T ... 
- AIX 5335端口IBM WebSphere应用服务器关闭连接信息泄露漏洞的修复
		今天按要求协助进行漏洞修复,有个“IBM WebSphere应用服务器关闭连接信息泄露漏洞”,一直没太搞清是不是没打补丁引起的问题. 感觉同样的安装有的报这漏洞有的不报,而报的有的是应用端口,有时是控 ... 
随机推荐
- javascript中的location的用法
			javascript中的location.href有很多种用法,主要如下. self.location.href="/url" 当前页面打开URL页面 location.href= ... 
- LeetCode——230. 二叉搜索树中第K小的元素
			给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素. 说明: 你可以假设 k 总是有效的,1 ≤ k ≤ 二叉搜索树元素个数. 示例 1: 输入: root = ... 
- python库文件下载地址(持续更新)
			numpy https://pypi.org/project/numpy/#files PIL https://pypi.org/simple/pillow/ cv2 https://pypi.tun ... 
- tensorflowlite 分类模型从训练到安卓部署
			https://blog.csdn.net/qq_33200967/article/details/82773677 
- HDU-4004 The Frog's Games (分治)
			http://acm.hdu.edu.cn/showproblem.php?pid=4004 Problem Description The annual Games in frogs' kingdo ... 
- 理解python的可变参数
			以 str.format(*args,**kwargs) 为例. "type1:{},{},{},{}_type2:{a},{b},{c},{d}".format('a',2,*[ ... 
- 关于目录的操作|*|<>|opendir |readdir|unlink|find2perl|rename|readlink|oct()|utime
			#!/usr/bin/perl use strict; use warnings; foreach my $arg(@ARGV) { print "one is $arg\n"; ... 
- 再来看看Java的新特性——其他新特性
			关于剩余Java8新特性知识点总结,包含:默认方法.Optional.CompletableFuture.时间相关. 默认方法 默认方法皆在帮助Java新功能可以兼容低版本JDK已开发的程序. 比如说 ... 
- 上传excel文件,读取内容,增加事务写入数据库
			package com.inspur.icpmg.itss.asset.dao.impl; import com.inspur.icpmg.util.DBHelper; import org.apac ... 
- 使script.bin文件配置生效的驱动
			1.问题:在全志方案中如果需要设置上拉或者下拉模式,需要在script.bin(先转换为script.fex)中配置gpio口 如: 但是配置好后是不会生效的,需要写一个驱动来通过读取这个文件的gp ... 
