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


C# IMongoCollection.CountAsync方法代码示例

本文整理汇总了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;
 }
开发者ID:magicdict,项目名称:MongoCola,代码行数:10,代码来源:ConnectionInfo.cs

示例2: Execute

 protected override void Execute(IMongoCollection<BsonDocument> collection, bool async)
 {
     if (async)
     {
         collection.CountAsync(_filter, _options).GetAwaiter().GetResult();
     }
     else
     {
         collection.Count(_filter, _options);
     }
 }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:CountTest.cs

示例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(
开发者ID:jango2015,项目名称:MongoCola,代码行数:67,代码来源:FillCollectionInfoToTreeNode.cs

示例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);
 }
开发者ID:sshev4enko,项目名称:tandd,代码行数:8,代码来源:Program.cs

示例5: ExecuteAsync

 protected override Task ExecuteAsync(IMongoCollection<BsonDocument> collection)
 {
     return collection.CountAsync(_filter, _options);
 }
开发者ID:RainsSoft,项目名称:mongo-csharp-driver,代码行数:4,代码来源:CountTest.cs

示例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
					});
			}
		}
开发者ID:lexarchik,项目名称:BuildRevisionCounter,代码行数:18,代码来源:MongoUserRepository.cs


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