Esempio n. 1
0
 /// <summary>
 /// 查看指定属性值在表中是否有重复项
 /// </summary>
 /// <param name="objectId">当前对象ID</param>
 /// <param name="prop">属性名</param>
 /// <param name="val">属性值</param>
 /// <param name="ignoreDelete">是否忽略逻辑删除数据</param>
 /// <returns></returns>
 public bool HasRepeat(ObjectId objectId, string prop, string val, bool ignoreDelete = true)
 {
     try
     {
         var builder = Builders <T> .Filter;
         FilterDefinition <T> filter = builder.Eq(prop, val);
         if (ignoreDelete)
         {
             filter &= builder.Eq("IsDelete", false);
         }
         if (!(objectId == null || String.IsNullOrEmpty(objectId.ToString()) || objectId.Timestamp == 0 || objectId.Machine == 0 || objectId.Increment == 0))
         {
             filter &= builder.Ne("_id", objectId);
         }
         return(MongoCollection.CountDocuments(filter) > 0);
     }
     catch (System.TimeoutException te)
     {
         MongoLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString());
         throw;
     }
     catch (Exception ex)
     {
         MongoLog.Logger.Warning(ex, "操作异常终止。");
         throw;
     }
 }
Esempio n. 2
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)));
        }
Esempio n. 3
0
 public long Count(Expression <Func <T, bool> > sel) => MongoCollection.CountDocuments(sel);
Esempio n. 4
0
 public long Count() => MongoCollection.CountDocuments(Builders <T> .Filter.Empty);
 public long CountSync(Expression <Func <T, bool> > filter)
 {
     return(MongoCollection.CountDocuments(filter));
 }
Esempio n. 6
0
 public int Count(Expression <Func <T, bool> > filter)
 {
     return(unchecked ((int)MongoCollection.CountDocuments(filter)));
 }