コード例 #1
0
        public long GetCountByDate(DateTime?startTime, DateTime?endTime)
        {
            List <FilterDefinition <BsonDocument> > list = new List <FilterDefinition <BsonDocument> >();

            if (startTime != null)
            {
                list.Add(FilterBuilder.Gte("CreateTime", startTime.Value));
            }
            if (endTime != null)
            {
                list.Add(FilterBuilder.Lte("CreateTime", endTime.Value));
            }
            if (list.Count == 0)
            {
                return(MongoCollection.EstimatedDocumentCount());
            }
            return(MongoCollection.CountDocuments(FilterBuilder.And(list)));
        }