本文整理汇总了C#中IMongoCollection.CountAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoCollection.CountAsync方法的具体用法?C# IMongoCollection.CountAsync怎么用?C# IMongoCollection.CountAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoCollection
的用法示例。
在下文中一共展示了IMongoCollection.CountAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCollectionCnt
public static long GetCollectionCnt(IMongoCollection<BsonDocument> col)
{
long colCount = 0;
Expression<Func<BsonDocument, bool>> countfun = x => true;
var task = Task.Run(
async () => { colCount = await col.CountAsync(countfun); }
);
task.Wait();
return colCount;
}
示例2: Execute
protected override void Execute(IMongoCollection<BsonDocument> collection, bool async)
{
if (async)
{
collection.CountAsync(_filter, _options).GetAwaiter().GetResult();
}
else
{
collection.Count(_filter, _options);
}
}
示例3: FillCollectionInfoToTreeNode
//.........这里部分代码省略.........
TextType.CollectionNameSystemReplset) +
"(" + strShowColName + ")";
break;
case ConstMgr.CollectionNameReplsetMinvalid:
strShowColName =
GuiConfig.GetText(
TextType.CollectionNameReplsetMinvalid) + "(" + strShowColName + ")";
break;
case ConstMgr.CollectionNameUser:
strShowColName =
GuiConfig.GetText(TextType.CollectionNameUser) +
"(" +
strShowColName + ")";
break;
case ConstMgr.CollectionNameRole:
//New From 2.6
strShowColName =
GuiConfig.GetText(TextType.CollectionNameRole) +
"(" +
strShowColName + ")";
break;
case ConstMgr.CollectionNameSystemProfile:
strShowColName =
GuiConfig.GetText(
TextType.CollectionNameSystemProfile) +
"(" + strShowColName + ")";
break;
}
}
//Collection件数的表示
long colCount = 0;
Expression<Func<BsonDocument, bool>> countfun = x => true;
var task = Task.Run(
async () => { colCount = await col.CountAsync(countfun); }
);
task.Wait();
strShowColName = strShowColName + "(" + colCount + ")";
var mongoColNode = new TreeNode(strShowColName);
switch (col.CollectionNamespace.CollectionName)
{
case ConstMgr.CollectionNameGfsFiles:
mongoColNode.Tag = ConstMgr.GridFileSystemTag + ":" + mongoConnSvrKey + "/" + databaseName + "/" +
col.CollectionNamespace.CollectionName;
break;
case ConstMgr.CollectionNameUser:
mongoColNode.Tag = ConstMgr.UserListTag + ":" + mongoConnSvrKey + "/" + databaseName + "/" +
col.CollectionNamespace.CollectionName;
break;
default:
mongoColNode.Tag = TagInfo.CreateTagInfo(mongoConnSvrKey, databaseName,
col.CollectionNamespace.CollectionName);
break;
}
//MongoCollection mongoCol = mongoDB.GetCollection(strColName);
////Start ListIndex
//var mongoIndexes = new TreeNode("Indexes");
//var indexList = mongoCol.GetIndexes();
IAsyncCursor<BsonDocument> indexCursor = null;
task = Task.Run(
async () => { indexCursor = await col.Indexes.ListAsync(); }
);
task.Wait();
List<BsonDocument> indexDocs = null;
task = Task.Run(
示例4: CountAsync
/// <summary>
/// Count documents (SQL=rows) in the collection (SQL=table).
/// </summary>
private static async Task CountAsync(IMongoCollection<BsonDocument> collection)
{
long count = await collection.CountAsync(new BsonDocument());
Console.WriteLine("\n[DB]{0}.[Collection]{1} : collection.Count = {2}", collection.Database.DatabaseNamespace.DatabaseName, collection.CollectionNamespace.CollectionName, count);
}
示例5: ExecuteAsync
protected override Task ExecuteAsync(IMongoCollection<BsonDocument> collection)
{
return collection.CountAsync(_filter, _options);
}
示例6: CreateAdmin
private async Task CreateAdmin(IMongoCollection<UserModel> users)
{
await users.Indexes.CreateOneAsync(
Builders<UserModel>.IndexKeys.Ascending(u => u.Name),
new CreateIndexOptions { Unique = true, });
if (await users.CountAsync(_ => true) == 0)
{
await users
.InsertOneAsync(
new UserModel
{
Name = AdminName,
Password = AdminPassword,
Roles = AdminRoles
});
}
}