本文整理汇总了C#中MongoDB.Driver.MongoClientSettings类的典型用法代码示例。如果您正苦于以下问题:C# MongoClientSettings类的具体用法?C# MongoClientSettings怎么用?C# MongoClientSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoClientSettings类属于MongoDB.Driver命名空间,在下文中一共展示了MongoClientSettings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetSettings
MongoClientSettings GetSettings()
{
if (String.IsNullOrEmpty(MongoSettings.ConnectionString))
{
throw new ArgumentNullException("Connection string not found.");
}
if (String.IsNullOrEmpty(MongoSettings.Database))
{
throw new ArgumentNullException("Database string not found.");
}
var ips = MongoSettings.ConnectionString.Split(';');
var servicesList = new List<MongoServerAddress>();
foreach (var ip in ips)
{
var host = ip.Split(':')[0];
var port = Convert.ToInt32(ip.Split(':')[1]);
servicesList.Add(new MongoServerAddress(host, port));
}
var setting = new MongoClientSettings();
setting.ReplicaSetName = MongoSettings.ReplicaSetName;
//集群中的服务器列表
setting.Servers = servicesList;
return setting;
}
开发者ID:ideayapai,项目名称:docviewer,代码行数:31,代码来源:MongoContext.cs
示例2: GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings
public void GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings()
{
var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
var servers = new[] { new MongoServerAddress("localhost"), new MongoServerAddress("127.0.0.1", 30000), new MongoServerAddress("[::1]", 27018) };
var sslSettings = new SslSettings
{
CheckCertificateRevocation = true,
EnabledSslProtocols = SslProtocols.Tls
};
var clientSettings = new MongoClientSettings
{
ApplicationName = "app1",
ConnectionMode = ConnectionMode.ReplicaSet,
ConnectTimeout = TimeSpan.FromSeconds(1),
Credentials = credentials,
GuidRepresentation = GuidRepresentation.Standard,
HeartbeatInterval = TimeSpan.FromSeconds(7),
HeartbeatTimeout = TimeSpan.FromSeconds(8),
IPv6 = true,
MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
MaxConnectionPoolSize = 10,
MinConnectionPoolSize = 5,
ReplicaSetName = "rs",
LocalThreshold = TimeSpan.FromMilliseconds(20),
Servers = servers,
ServerSelectionTimeout = TimeSpan.FromSeconds(5),
SocketTimeout = TimeSpan.FromSeconds(4),
SslSettings = sslSettings,
UseSsl = true,
VerifySslCertificate = true,
WaitQueueSize = 20,
WaitQueueTimeout = TimeSpan.FromSeconds(6)
};
var subject = new ClusterRegistry();
using (var cluster = subject.GetOrCreateCluster(clientSettings.ToClusterKey()))
{
var endPoints = new EndPoint[]
{
new DnsEndPoint("localhost", 27017),
new IPEndPoint(IPAddress.Parse("127.0.0.1"), 30000),
new IPEndPoint(IPAddress.Parse("[::1]"), 27018)
};
cluster.Settings.ConnectionMode.Should().Be(ClusterConnectionMode.ReplicaSet);
cluster.Settings.EndPoints.Equals(endPoints);
cluster.Settings.ReplicaSetName.Should().Be("rs");
cluster.Settings.ServerSelectionTimeout.Should().Be(clientSettings.ServerSelectionTimeout);
cluster.Settings.PostServerSelector.Should().NotBeNull().And.Subject.Should().BeOfType<LatencyLimitingServerSelector>();
cluster.Settings.MaxServerSelectionWaitQueueSize.Should().Be(20);
cluster.Description.Servers.Select(s => s.EndPoint).Should().Contain(endPoints);
// TODO: don't know how to test the rest of the settings because they are all private to the cluster
}
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:59,代码来源:ClusterRegistryTests.cs
示例3: parse_from_connection_string
protected void parse_from_connection_string( string connection_string ) {
var mongo_url = MongoUrl.Create( connection_string );
ConnectionString = connection_string;
DatabaseName = mongo_url.DatabaseName;
MongoClientSettings = MongoClientSettings.FromUrl( mongo_url );
}
开发者ID:magriffsla,项目名称:Mongo.Entity,代码行数:8,代码来源:DatabaseSettings.cs
示例4: GetDatabase
public IMongoDatabase GetDatabase(string user, string password, string db = defaultDB) {
var credential = MongoCredential.CreateMongoCRCredential(db, user, password);
var settings = new MongoClientSettings { Credentials = new[] { credential } };
var mongoClient = new MongoClient(settings);
return GetDatabase(mongoClient, db);
}
开发者ID:DamienSaillard,项目名称:AppliMongoDB,代码行数:7,代码来源:MyMongoClient.cs
示例5: ToMongoClientSettings
/// <summary>
/// Converts the current instance to a <see cref="MongoClientSettings"/>.
/// </summary>
/// <returns>The current instance as a <see cref="MongoClientSettings"/>.</returns>
public virtual MongoClientSettings ToMongoClientSettings()
{
MongoClientSettings settings;
if (this.Servers == null || !this.Servers.Any())
{
settings = new MongoClientSettings
{
Server = new MongoServerAddress(this.Host, this.Port)
};
}
else
{
// Support multiple servers if needed (e.g. replication)
settings = new MongoClientSettings
{
Servers = this.Servers.Select(s => new MongoServerAddress(s.Host, s.Port))
};
}
// Set replica set
settings.ReplicaSetName = this.ReplicaSet;
if (this.Authenticate)
{
settings.Credentials = new[] { MongoCredential.CreateMongoCRCredential(this.Database, this.Username, this.Password) };
}
return settings;
}
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:33,代码来源:MongoConfiguration.cs
示例6: Connect
public override bool Connect() {
bool opened = true;
if (this.Client == null) {
try {
MongoClientSettings settings = new MongoClientSettings();
if (this.Settings.Hostname != null && this.Settings.Port.HasValue == true) {
settings.Server = new MongoServerAddress(this.Settings.Hostname, (int)this.Settings.Port.Value);
}
else if (this.Settings.Hostname != null) {
settings.Server = new MongoServerAddress(this.Settings.Hostname);
}
if (this.Database != null && this.Settings.Username != null && this.Settings.Password != null) {
settings.Credentials = new List<MongoCredential>() {
MongoCredential.CreateMongoCRCredential(this.Settings.Database, this.Settings.Username, this.Settings.Password)
};
}
this.Client = new MongoClient(settings);
this.Database = this.Client.GetServer().GetDatabase(this.Settings.Database);
}
catch {
opened = false;
}
}
return opened;
}
开发者ID:EBassie,项目名称:Potato,代码行数:31,代码来源:MongoDbDriver.cs
示例7: TestRealMongo
public ActionResult TestRealMongo()
{
//Connect to MongoDB in C# with Credentials
var credential = MongoCredential.CreateMongoCRCredential("alertsmd", "rangle", "m3anstack");
//Server settings
var settings = new MongoClientSettings
{
Credentials = new[] { credential },
Server = new MongoServerAddress("ds033757.mongolab.com",33757)
};
//Get a Reference to the Client Object
var mongoClient = new MongoClient(settings);
var mongoServer = mongoClient.GetServer();
var database = mongoServer.GetDatabase("alertsmd");
var collections = database.GetCollectionNames();
var usersCollection = database.GetCollection("users");
var mconditions = database.GetCollection("conditions").FindAll();
var mfeedbacks = database.GetCollection("feedbacks").FindAll();
var mprofiles = database.GetCollection("profiles").FindAll();
var msessions = database.GetCollection("sessions").FindAll();
var msymptoms = database.GetCollection("symptoms").FindAll();
var msystem_indexes = database.GetCollection("system.indexes").FindAll();
var msystem_users = database.GetCollection("system.users").FindAll();
var muserDatas = database.GetCollection("userDatas").FindAll();
var musers = database.GetCollection("users").FindAll();
return View();
}
开发者ID:pabloelustondo,项目名称:WellCastServer,代码行数:33,代码来源:TestMongoController.cs
示例8: LocalContext
public LocalContext()
{
MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress("localhost", 27017);
//settings.Server = new MongoServerAddress("192.168.0.103", 27017);
var client = new MongoClient(settings);
Database = client.GetDatabase("admin");
}
开发者ID:nithin8702,项目名称:MyRepository,代码行数:8,代码来源:LocalContext.cs
示例9: MongoDashboardContext
public MongoDashboardContext()
{
var settings = new MongoClientSettings();
settings.Server = new MongoServerAddress("127.0.0.1");
var client = new MongoClient(settings);
var database = client.GetDatabase("Workspaces");
Dashboards = database.GetCollection<Dashboard>("Dashboard");
}
开发者ID:florinszilagyi,项目名称:storeme,代码行数:8,代码来源:DashboardContext.cs
示例10: MongoStore
public MongoStore(string db)
{
var clientSettings = new MongoClientSettings();
//clientSettings.Server = new MongoServerAddress("mongodb://host:22666");
var mongo = new MongoClient("mongodb://localhost:22666");
var l = mongo.ListDatabasesAsync().Result;
_mongodb = mongo.GetDatabase(db);
}
开发者ID:grrrrinaldi,项目名称:emveeseefive,代码行数:8,代码来源:MongoStore.cs
示例11: GetTestDatabase
protected static MongoDatabase GetTestDatabase()
{
var settings = new MongoClientSettings
{
Server = new MongoServerAddress("localhost")
};
return new MongoClient(settings).GetServer().GetDatabase("mongo-learning");
}
开发者ID:hanu412,项目名称:mongo-learning,代码行数:8,代码来源:TestsBase.cs
示例12: Create
public IMongoDatabase Create()
{
MongoClientSettings setting = new MongoClientSettings();
setting.Server = new MongoServerAddress(_serverAddress, 27017);
var mongoClient = new MongoClient(setting);
var db = mongoClient.GetDatabase(_databaseName);
return db;
}
开发者ID:AChehre,项目名称:Paran,代码行数:9,代码来源:ConnectionFactory.cs
示例13: MongoOptimisticDataStore
public MongoOptimisticDataStore(MongoClientSettings settings, string databaseName, string collectionName)
{
MongoClient client = new MongoClient(settings);
this.Server = client.GetServer();
this.CollectionName = collectionName;
this.Database = this.Server.GetDatabase(databaseName);
SetCollection();
this.IsConnected = true;
}
开发者ID:cyberprune,项目名称:SnowMaker,代码行数:9,代码来源:MongoOptimisticDataStore.cs
示例14: BookController
public BookController()
{
_repo = new Repository();
string connectionString = "mongodb://localhost:27017/";
var mongoClientSettings = new MongoClientSettings();
mongoClientSettings.Server = new MongoServerAddress(connectionString);
var client = new MongoClient();
var db = client.GetDatabase("BookMVC");
var collection = db.GetCollection<Book>("Book");
}
开发者ID:mattwoPhre,项目名称:MongoDB,代码行数:10,代码来源:BookController.cs
示例15: UseMongoStorage
public static MongoStorage UseMongoStorage(this IBootstrapperConfiguration configuration,
MongoClientSettings mongoClientSettings,
string databaseName)
{
MongoStorage storage = new MongoStorage(mongoClientSettings, databaseName);
configuration.UseStorage(storage);
return storage;
}
开发者ID:Trov,项目名称:Hangfire.Mongo,代码行数:10,代码来源:MongoBootstrapperConfigurationExtensions.cs
示例16: HangfireDbContext
/// <summary>
/// Constructs context with Mongo client settings and database name
/// </summary>
/// <param name="mongoClientSettings">Client settings for MongoDB</param>
/// <param name="databaseName">Database name</param>
/// <param name="prefix">Collections prefix</param>
public HangfireDbContext(MongoClientSettings mongoClientSettings, string databaseName, string prefix = "hangfire")
{
_prefix = prefix;
MongoClient client = new MongoClient(mongoClientSettings);
Database = client.GetDatabase(databaseName);
ConnectionId = Guid.NewGuid().ToString();
}
开发者ID:Trov,项目名称:Hangfire.Mongo,代码行数:16,代码来源:HangfireDbContext.cs
示例17: Start
public static MongoDbAuditStoreProvider Start(this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider)
{
var settings = new MongoClientSettings
{
ClusterConfigurator = cb => cb.ConfigureCluster(c => c.With(serverSelectionTimeout:
TimeSpan.FromMilliseconds(@mongoDbAuditStoreProvider.TimeoutMilliseconds))),
Server = new MongoServerAddress(@mongoDbAuditStoreProvider.ServerName)
};
@mongoDbAuditStoreProvider.Client = new MongoClient(settings);
return @mongoDbAuditStoreProvider;
}
开发者ID:johannbrink,项目名称:EFAuditing,代码行数:11,代码来源:MongoDbAuditStoreProviderExtensions.cs
示例18: GetMongoDatabase
public static MongoDatabase GetMongoDatabase()
{
string connectionString = "mongodb://localhost:27017/";
var mongoClientSettings = new MongoClientSettings();
mongoClientSettings.Server = new MongoServerAddress(connectionString);
var client = new MongoClient();
var db = client.GetDatabase("BookMVC");
var collection = db.GetCollection<Book>("Book");
return client.GetServer().GetDatabase("BookMVC");
}
开发者ID:mattwoPhre,项目名称:MongoDB,代码行数:11,代码来源:MongoSessionFactory.cs
示例19: MongoContext
public MongoContext()
{
var credentials = MongoCredential.CreateMongoCRCredential("TestDB", "admin", "123456");
var settings = new MongoClientSettings
{
Credentials = new [] {credentials}
};
var client = new MongoClient(settings);
database = client.GetDatabase("TestDB");
//database = server.GetDatabase("TestDB");
}
开发者ID:imshah,项目名称:Frame,代码行数:11,代码来源:MongoContext.cs
示例20: initMongoDB
private static void initMongoDB(string ip, int port)
{
MongoClientSettings mongoSettings = new MongoClientSettings();
mongoSettings.Servers = new List<MongoServerAddress>()
{
new MongoServerAddress (ip,port)
};
mongoClient = new MongoClient(mongoSettings);
MongoServer mongoServer = mongoClient.GetServer();
MongoDatabase mongoDB = mongoServer.GetDatabase("V5");
dataCollection = mongoDB.GetCollection("MessagePack");
}
开发者ID:soarowl,项目名称:my-project-sjsquotationinterface,代码行数:12,代码来源:Program.cs
注:本文中的MongoDB.Driver.MongoClientSettings类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论