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


C# MongoCollection.Count方法代码示例

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


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

示例1: Find

        public IEnumerable<IDictionary<string, object>> Find(MongoCollection<BsonDocument> collection, SimpleQuery query, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
        {
            var builder = MongoQueryBuilder.BuildFrom(query);

            unhandledClauses = builder.UnprocessedClauses;

            if (builder.IsTotalCountQuery)
            {
                long count;
                if (builder.Criteria == null)
                    count = collection.Count();
                else
                    count = collection.Count(_expressionFormatter.Format(builder.Criteria));

                //TODO: figure out how to make count a long
                builder.SetTotalCount((int)count);
            }

            if (!builder.SkipCount.HasValue && builder.TakeCount.HasValue && builder.TakeCount.Value == 1)
                return new[] { FindOne(collection, builder.Criteria) };

            var cursor = CreateCursor(collection, builder.Criteria);

            ApplyFields(cursor, builder.Columns);
            ApplySorting(cursor, builder.Order);
            ApplySkip(cursor, builder.SkipCount);
            ApplyTake(cursor, builder.TakeCount);

            var aliases = builder.Columns.OfType<ObjectReference>().ToDictionary(x => ExpressionFormatter.GetFullName(x), x => x.GetAlias());

            return cursor.Select(x => x.ToSimpleDictionary(aliases));
        }
开发者ID:kppullin,项目名称:Simple.Data.MongoDB,代码行数:32,代码来源:MongoAdapterFinder.cs

示例2: CreateAndInsertMultipleDocumentIntoCollection

        /// <summary>
        /// Demo inserting multiple document into collection.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void CreateAndInsertMultipleDocumentIntoCollection(MongoCollection<Order> orders)
        {
            Console.WriteLine("\n\n======= Insert Multiple Documents =======");
            Console.WriteLine(string.Format("Document Count Before Insert: [ {0} ]", orders.Count()));

            // Create new orders.
            var order1 = new Order
                         	{
                         			OrderAmount = 100.23,
                         			CustomerName = "Bugs Bunny"
                         	};
            var order2 = new Order
                         	{
                         			OrderAmount = 0.01,
                         			CustomerName = "Daffy Duck"
                         	};

            IEnumerable<Order> orderList = new List<Order> { order1, order2 };

            // Insert an IEnumerable.
            orders.InsertBatch(orderList);

            Console.WriteLine(string.Format("Inserted: {0}", order1));
            Console.WriteLine(string.Format("Inserted: {0}", order2));

            Console.WriteLine(string.Format("Document Count After Insert: [ {0} ]", orders.Count()));
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:31,代码来源:Program.cs

示例3: DeleteAllDocumentsFromCollection

        /// <summary>
        /// Demo deleting documents from collection.
        /// </summary>
        /// <param name="orders">The orders.</param>
        static void DeleteAllDocumentsFromCollection( MongoCollection< Order > collection )
        {
            Console.WriteLine( "\n\n======= Delete Documents =======" );
            Console.WriteLine( string.Format( "Document Count Before Delete: [ {0} ]", collection.Count() ) );

            // Delete documents matching a criteria.
            collection.Remove( new {CustomerName = "Elmer Fudd"} );
            Console.WriteLine( string.Format( "Document Count After Deleting Elmer Fudd: [ {0} ]", collection.Count() ) );

            // Delete all docs.
            collection.Remove( new {} );

            Console.WriteLine( "Deleted all docs" );
            Console.WriteLine( string.Format( "Document Count After Deleting All Docs: [ {0} ]", collection.Count() ) );
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:19,代码来源:Program.cs

示例4: CoverDB

 public static void CoverDB(string player, MongoCollection oldPlayer, MongoCollection newPlayer)
 {
     Console.WriteLine("正在合并:" + player);
     int show = 0;
     int count = 0;
     var dates = oldPlayer.FindAllAs<BsonDocument>();
     foreach (var v in dates)
     {
         BsonValue key;
         if (v.TryGetValue("_id", out key))
         {
             if (newPlayer.Count(Query.EQ("_id", key)) <= 0)
             {
                 count++;
                 newPlayer.Save(v);
             }
         }
         show++;
         if (show % 1000 == 0)
         {
             Console.WriteLine("正在合并:" + show);
         }
     }
     Console.WriteLine(player + ":" + count);
 }
开发者ID:abel,项目名称:sinan,代码行数:25,代码来源:MergerDB.cs

示例5: ReloadExisting

        public void ReloadExisting()
        {
            connectionString = "mongodb://localhost/?safe=true";
            server = MongoServer.Create(connectionString);
            habraDb = server.GetDatabase("habr", SafeMode.True);
            posts = habraDb.GetCollection<Post>("posts");
            existedBeforeCount = posts.Count();

            using (client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                foreach (var post in posts.FindAll())
                {
                    try
                    {
                        Console.Clear();
                        Console.WriteLine(string.Format("Reloaded: {0} posts of {1} possible", reloadedCount, existedBeforeCount));
                        Console.WriteLine("Processing: " + post.Url);
                        Console.WriteLine("Loading...");
                        string pageContent = client.DownloadString(post.Url);
                        Console.WriteLine("Parsing...");
                        ParsePostPage(post.Url, pageContent);

                    }
                    catch { }
                }
            }
        }
开发者ID:opcheese,项目名称:DlyaCrawlerov,代码行数:28,代码来源:Crawler.cs

示例6: DownloadNew

        public void DownloadNew()
        {
            connectionString = "mongodb://localhost/?safe=true";
            server = MongoServer.Create(connectionString);
            habraDb = server.GetDatabase("habr", SafeMode.True);
            posts = habraDb.GetCollection<Post>("posts");
            existedBeforeCount = posts.Count();

            int postListPage = 1;
            while (downloadedCount < NEEDED_POST_COUNT)
            {
                using (client = new WebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    try
                    {
                        string url = "http://habrahabr.ru/posts/collective/";
                        if (postListPage > 1)
                            url += string.Format("page{0}/", postListPage);
                        string pageContent = client.DownloadString(url);
                        ParsePostListPage(pageContent);
                        postListPage++;
                    }
                    catch { }
                }
            }
        }
开发者ID:opcheese,项目名称:DlyaCrawlerov,代码行数:27,代码来源:Crawler.cs

示例7: CreateAndInsertSingleDocumentIntoCollection

        /// <summary>
        /// Inserts a new document.
        /// </summary>
        /// <param name="collection">The orders.</param>
        private static void CreateAndInsertSingleDocumentIntoCollection(MongoCollection<Order> collection)
        {
            Console.WriteLine("\n\n======= Insert Multiple Documents =======");
            Console.WriteLine(string.Format("Document Count Before Insert: [ {0} ]", collection.Count()));

            // Create a new order.
            var order = new Order()
            {
                OrderAmount = 57.22,
                CustomerName = "Elmer Fudd"
            };

            // Add the new order to the mongo orders colleciton.
            collection.Insert(order);
            Console.WriteLine(string.Format("Inserted: {0}", order));

            Console.WriteLine(string.Format("Document Count After Insert: [ {0} ]", collection.Count()));
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:22,代码来源:Program.cs

示例8: CheckLocExists

 private string CheckLocExists(double latitude, double longitude, MongoCollection<Location> locations, out string statusMessage)
 {
     statusMessage = null;
     string locationID = null;
     try
     {
         if (locations.Count() > 0)
         {
             var locationQuery = Query.And(Query.EQ("longitude", longitude), Query.EQ("latitude", latitude));
             var existedLocation = locations.FindOne(locationQuery);
             if (existedLocation != null)
                 locationID = (existedLocation as Location).locationID;
             //File.WriteAllText(@"C:\locations.txt", "(current locationQuery) = " + locationQuery.ToJson() + " (current existedLocation) = " + existedLocation.ToJson() + " locationID = " + locationID + " " + DateTime.Now);
         }
     }
     catch (Exception e)
     {
         locationID = null;
         statusMessage = "An exception has occured in CheckLocExists method. " + e.Message;
     }
     return locationID;
 }
开发者ID:CDPGroup19,项目名称:backend,代码行数:22,代码来源:BackendService.svc.cs

示例9: CheckUserExists

 private string CheckUserExists(string userName, MongoCollection<UserLegitimation> users, out string statusMessage)
 {
     statusMessage = null;
     string userID = null;
     try
     {
         if (users.Count() > 0)
         {
             var userQuery = Query.EQ("userName", userName);
             var existedUser = users.FindOne(userQuery);
             if (existedUser != null)
                 userID = (existedUser as UserLegitimation).userID;
         }
     }
     catch (Exception e)
     {
         userID = null;
         statusMessage = "An exception has occured in CheckUserExists method. " + e.Message;
     }
     return userID;
 }
开发者ID:CDPGroup19,项目名称:backend,代码行数:21,代码来源:BackendService.svc.cs

示例10: DoesCounterCollectionHaveDocuments

        public bool DoesCounterCollectionHaveDocuments(MongoCollection<BsonDocument> counterCollection)
        {
            long count = counterCollection.Count();

            return count > 0;
        }
开发者ID:sgh1986915,项目名称:.net-braintree-spa,代码行数:6,代码来源:CounterDal.cs


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