本文整理汇总了C#中MongoDB.Driver.MongoClient.ListDatabases方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClient.ListDatabases方法的具体用法?C# MongoClient.ListDatabases怎么用?C# MongoClient.ListDatabases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClient
的用法示例。
在下文中一共展示了MongoClient.ListDatabases方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainAsync
static async Task MainAsync(string[] args)
{
var connectionString2 = "mongodb://localhost:27017,localhost:27018?replicaset=funny";
var connectionString = "mongodb://localhost:27017";
var client = new MongoClient(connectionString);
var dbs= client.ListDatabases().ToList();
/**
foreach (MongoDB.Bson.BsonDocument d in dbs)
{
Console.WriteLine(d.ToString());
}
**/
var workdb = client.GetDatabase("test");
var personCollection = workdb.GetCollection<Person>("person");
var builder = Builders<Person>.Filter;
FilterDefinition<Person> searchFilter = builder.And(builder.Lt("Age", 51) & builder.Eq("Name", "jones"));
if (personCollection != null)
{
await workdb.DropCollectionAsync("person");
await AddDocuments(personCollection);
/**
//Search for only "jones" with age lte 30 by creating BSON Doc filter.
var searchFilter = new BsonDocument("$and", new BsonArray
{
new BsonDocument("Age", new BsonDocument("$lte", 300)),
new BsonDocument("Name", "jones")
});
**/
await findDocuments(personCollection, searchFilter);
}
doReplace(personCollection);
await findDocuments(personCollection, searchFilter);
}
示例2: 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, new MongoClientSettings());
if (async)
{
client.ListDatabasesAsync().GetAwaiter().GetResult();
}
else
{
client.ListDatabases();
}
var call = operationExecutor.GetReadCall<IAsyncCursor<BsonDocument>>();
call.Operation.Should().BeOfType<ListDatabasesOperation>();
}
示例3: CheckConnection
private Boolean CheckConnection(String connection)
{
var url = new MongoUrl(connection);
var client = new MongoClient(url);
Task.Factory.StartNew(() =>
{
var allDb = client.ListDatabases();
}); //forces a database connection
Int32 spinCount = 0;
ClusterState clusterState;
while ((clusterState = client.Cluster.Description.State) != ClusterState.Connected &&
spinCount++ < 100)
{
Thread.Sleep(20);
}
return clusterState == MongoDB.Driver.Core.Clusters.ClusterState.Connected;
}