/// <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; } }
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))); }
public long Count(Expression <Func <T, bool> > sel) => MongoCollection.CountDocuments(sel);
public long Count() => MongoCollection.CountDocuments(Builders <T> .Filter.Empty);
public long CountSync(Expression <Func <T, bool> > filter) { return(MongoCollection.CountDocuments(filter)); }
public int Count(Expression <Func <T, bool> > filter) { return(unchecked ((int)MongoCollection.CountDocuments(filter))); }