本文整理汇总了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();
}
示例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;
}
示例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;
}
}
示例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();
}
示例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;
}