本文整理汇总了C#中MongoDB.Driver.MongoClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClient.Connect方法的具体用法?C# MongoClient.Connect怎么用?C# MongoClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClient
的用法示例。
在下文中一共展示了MongoClient.Connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConnection
/// <summary>
/// Tests the MongoDB connection.
/// </summary>
/// <param name="connectionString">MongoDB connection string to use to connect.</param>
public void TestConnection(string connectionString)
{
if (String.IsNullOrEmpty(connectionString))
throw Errors.ConnectionStringMissing();
var server = new MongoClient(connectionString).GetServer();
server.Connect();
server.Disconnect();
}
示例2: Initialize
public void Initialize()
{
var url = new MongoUrl(configuration.ConnectionString);
MongoRetryPolicy.ExecuteAction(() =>
{
var server = new MongoClient(url).GetServer();
server.Connect();
var collection = server.GetDatabase(url.DatabaseName).GetCollection(configuration.Collection);
var mongoCursor = String.IsNullOrEmpty(configuration.Query)
? collection.FindAll()
: collection.Find(new QueryDocument(BsonSerializer.Deserialize<BsonDocument>(configuration.Query)));
documentsCursor = mongoCursor.SetFields(ParseProjection(configuration.Projection)).GetEnumerator();
});
}
示例3: Connect
public static MongoServer Connect()
{
MongoServer server = new MongoClient(DatabaseSettings.Instance.ConnectionString).GetServer();
server.Connect();
return server;
}