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


C# MongoClient.ListDatabases方法代码示例

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

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

示例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;
        }
开发者ID:ProximoSrl,项目名称:Jarvis.DocumentStore,代码行数:18,代码来源:DocumentStoreBootstrapper.cs


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