• 在C#中mongohelper的初始化


    MongoClientSettings mongoSettings = new MongoClientSettings();
    TimeSpan t = new TimeSpan(100);
    mongoSettings.ConnectTimeout = t;//设置连接超时时长
    mongoSettings.MaxConnectionPoolSize = 2000;//设置连接池最大连接数
    MongoCredential cr = MongoCredential.CreateMongoCRCredential("数据库名", "用户名", "密码");//添加用户名、密码
    List<MongoCredential> credentials = new List<MongoCredential>();
    credentials.Add(cr);
    mongoSettings.Credentials = credentials;
    mongoSettings.Server =new MongoServerAddress("192.168.1.1",27017);//服务器地址
    mongoSettings.ReadPreference = new ReadPreference(ReadPreferenceMode.Primary);
    mongoClient = new MongoClient(mongoSettings);
    mongoServer = mongoClient .GetServer();
    mongoDataBase = mongoServer.GetDatabase(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString.Split('|')[1]);
    mongoCollection = mongoDataBase.GetCollection(tableName);

  • 相关阅读:
    接口和抽象类的区别联系(一)
    股指期货-基础知识
    A股魔咒
    .NET 分布式架构
    Spring Cloud Netflix
    现货、期货、期权、权证
    复盘-20190321
    复盘思考
    公司法
    2019年行情思考
  • 原文地址:https://www.cnblogs.com/zhenfeng/p/4222519.html
Copyright © 2020-2023  润新知