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


C# IMongoDatabase.ListCollectionsAsync方法代码示例

本文整理汇总了C#中IMongoDatabase.ListCollectionsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoDatabase.ListCollectionsAsync方法的具体用法?C# IMongoDatabase.ListCollectionsAsync怎么用?C# IMongoDatabase.ListCollectionsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMongoDatabase的用法示例。


在下文中一共展示了IMongoDatabase.ListCollectionsAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsCollectionExistsAsync

        public async Task<bool> IsCollectionExistsAsync(IMongoDatabase mongoDatabase,string collectionName)
        {
            var filter = new BsonDocument("name", collectionName);

            //filter by collection name
            var collections = await mongoDatabase.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter });
            //check for existence
            return (await collections.ToListAsync()).Any();
        }
开发者ID:AzharIqbal84,项目名称:ForwardMongoLogger,代码行数:9,代码来源:MongoDbHelper.cs

示例2: maplistcontent

        public async Task<HttpResponseMessage> maplistcontent(string area)
        {


            _mongoClient = new MongoClient(ConfigurationManager.ConnectionStrings["MongoDBContext"].ConnectionString);
            _mongoDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["civilgisDBname"]);

            //_mongoDatabase.ListCollectionsAsync
           // List<BsonDocument> list = _mongoDatabase.ListCollectionsAsync().Result.ToListAsync().Result;

            string result = "[";
            int count = 0;
            area = area + "_";
            using (var cursor = await _mongoDatabase.ListCollectionsAsync())
            {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var bsonDocument in batch)
                    {
                        var _collection_nm = bsonDocument.GetValue("name");
                        
                        
                        string rd = _collection_nm.ToString();

                        if (rd.Contains(area) == true)
                        {
                            // output format: [[1,"oc_address"],[2,"oc_bounds"],[3,"oc_cities"],[4,"oc_education_facility"],[5,"oc_fire_grid"],[6,"oc_fire_stations"],[7,"oc_hospitals"],[8,"oc_hwy_majorrd"],[9,"oc_rails"],[10,"oc_streets"],[11,"oc_water"]]

                            count++;
                            result = result + '[' + Convert.ToString(count)+ ',' + '"' +rd + '"' +"],";
                            
                        }//if
                    }
                }



            }// using

            // remove last ","
            result = result.Remove(result.Length - 1);

            result = result + "]";



            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result, "text/plain");



            return response;

        }
开发者ID:hoogw,项目名称:civilgis_net_1,代码行数:54,代码来源:GeojsonController.cs

示例3: CollectionExistsAsync

		private async Task<bool> CollectionExistsAsync(IMongoDatabase database, string collectionName)
		{
			try {
				var filter = new BsonDocument("name", collectionName);
				//filter by collection name
				var collections = database.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter });
				//check for existence
				return (await collections.Result.ToListAsync()).Any();
			}
			catch {
				throw;
			}
		}
开发者ID:RafaelDelboni,项目名称:Angular-WebAPI-MongoDB-TokenAuth,代码行数:13,代码来源:Bootstrapper.cs

示例4: CollectionExists

        private bool CollectionExists(IMongoDatabase db, string collectionName)
        {
            var filter = new BsonDocument("name", collectionName);

            return db.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter })
                     .Result
                     .ToListAsync()
                     .Result
                     .Any();
        }
开发者ID:seanfitzg,项目名称:log4mongo-net,代码行数:10,代码来源:MongoDBAppender.cs

示例5: CheckIfTheCollectionExist

 /// <summary>
 /// Check if the collection exist
 /// </summary>
 /// <param name="db"></param>
 /// <param name="collectionName"></param>
 /// <returns></returns>
 protected virtual bool CheckIfTheCollectionExist(IMongoDatabase db, string collectionName)
 {
     using (var cursor = db.ListCollectionsAsync().Result)
     {
         var collections = cursor.ToListAsync();
         foreach (var collection in collections.Result)
             if (collection["name"] == collectionName)
                 return true;
     }
     return false;
 }
开发者ID:dotadam,项目名称:NLog.MongoAsync,代码行数:17,代码来源:LogRepository.cs


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