本文整理汇总了C#中MongoDB.Driver.MongoClient.ListDatabasesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClient.ListDatabasesAsync方法的具体用法?C# MongoClient.ListDatabasesAsync怎么用?C# MongoClient.ListDatabasesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClient
的用法示例。
在下文中一共展示了MongoClient.ListDatabasesAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: ListDatabasesAsync_should_invoke_the_correct_operation
public async Task ListDatabasesAsync_should_invoke_the_correct_operation()
{
var operationExecutor = new MockOperationExecutor();
var client = new MongoClient(operationExecutor);
await client.ListDatabasesAsync();
var call = operationExecutor.GetReadCall<IAsyncCursor<BsonDocument>>();
call.Operation.Should().BeOfType<ListDatabasesOperation>();
}
示例3: GetDatabaseList
/// <summary>
/// 获得数据库列表
/// </summary>
/// <param name="client"></param>
/// <returns></returns>
public static List<BsonDocument> GetDatabaseList(MongoClient client)
{
//暂时返回一个同步的结果
IAsyncCursor<BsonDocument> databaseCursor = null;
var task = Task.Run(
async () => { databaseCursor = await client.ListDatabasesAsync(); }
);
task.Wait();
List<BsonDocument> databaseList = null;
task = Task.Run(
async () => { databaseList = await databaseCursor.ToListAsync(); }
);
task.Wait();
return databaseList;
}
示例4: ListDatabases_should_invoke_the_correct_operation
public void ListDatabases_should_invoke_the_correct_operation(
[Values(false, true)] bool async)
{
var operationExecutor = new MockOperationExecutor();
var client = new MongoClient(operationExecutor);
if (async)
{
client.ListDatabasesAsync().GetAwaiter().GetResult();
}
else
{
client.ListDatabases();
}
var call = operationExecutor.GetReadCall<IAsyncCursor<BsonDocument>>();
call.Operation.Should().BeOfType<ListDatabasesOperation>();
}
示例5: GetDatabase
private void GetDatabase(MongoSettings settings)
{
Require.NotNull(settings, "settings");
// Register conventions.
Register();
// To directly connect to a single MongoDB server
// (this will not auto-discover the primary even if it's a member of a replica set)
var clientSettings = new MongoClientSettings
{
Server = new MongoServerAddress(settings.Host,settings.Port),
ClusterConfigurator = builder =>
{
builder.ConfigureCluster(s => s.With(serverSelectionTimeout: TimeSpan.FromSeconds(settings.Timeout)));
}
};
var client = new MongoClient(clientSettings);
this.Database = client.GetDatabase(settings.DatabaseName);
try
{
var result = client.ListDatabasesAsync();
result.Wait();
}
catch(AggregateException exception)
{
if (exception.InnerException is TimeoutException)
throw new UnreachableException(client, exception.InnerException as TimeoutException);
}
catch (Exception)
{
throw;
}
}
示例6: GetDatabaseInfoList
/// <summary>
/// 获得数据库定义列表
/// </summary>
/// <param name="client"></param>
/// <returns></returns>
public static List<BsonDocument> GetDatabaseInfoList(MongoClient client)
{
//暂时返回一个同步的结果
IAsyncCursor<BsonDocument> databaseCursor = null;
var task = Task.Run(
async () => { databaseCursor = await client.ListDatabasesAsync(); }
);
task.Wait();
List<BsonDocument> databaseList = null;
task = Task.Run(
async () => { databaseList = await databaseCursor.ToListAsync(); }
);
task.Wait();
databaseList.Sort((x, y) =>
{
if (x.GetElement("name").Value.ToString() == ConstMgr.DatabaseNameAdmin)
{
return -1;
}
else
{
return x.GetElement("name").Value.ToString().CompareTo(y.GetElement("name").Value.ToString());
}
});
return databaseList;
}