C# Mongo Client 2.4.2判断是否存在表

public async Task<bool> CollectionExistsAsync(string collectionName)
    {
        var filter = new BsonDocument("name", collectionName);
        //filter by collection name
        var collections = await GetDatabase().ListCollectionsAsync(new ListCollectionsOptions { Filter = filter });
        //check for existence
        return await collections.AnyAsync();
    }
posted @ 2017-02-15 15:21  94cool  阅读(1013)  评论(0编辑  收藏  举报