当前位置: 首页>>代码示例>>C#>>正文


C# MongoClient.ListDatabasesAsync方法代码示例

本文整理汇总了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);
 }
开发者ID:grrrrinaldi,项目名称:emveeseefive,代码行数:8,代码来源:MongoStore.cs

示例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>();
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:10,代码来源:MongoClientTests.cs

示例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;
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:20,代码来源:GetConnectionInfo.cs

示例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>();
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:19,代码来源:MongoClientTests.cs

示例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;
            }
        }
开发者ID:baozkan,项目名称:Tiktak,代码行数:36,代码来源:MongoContext.cs

示例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;
 }
开发者ID:magicdict,项目名称:MongoCola,代码行数:31,代码来源:ConnectionInfo.cs


注:本文中的MongoDB.Driver.MongoClient.ListDatabasesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。