public ICollection <PersistentEvent> GetMostRecent(string projectId, DateTime utcStart, DateTime utcEnd, PagingOptions paging, bool includeHidden = false, bool includeFixed = false, bool includeNotFound = true) { IMongoQuery query = Query.Null; if (utcStart != DateTime.MinValue) { query = query.And(Query.GTE(FieldNames.Date_UTC, utcStart.Ticks)); } if (utcEnd != DateTime.MaxValue) { query = query.And(Query.LTE(FieldNames.Date_UTC, utcEnd.Ticks)); } if (!includeHidden) { query = query.And(Query.NE(FieldNames.IsHidden, true)); } if (!includeFixed) { query = query.And(Query.NE(FieldNames.IsFixed, true)); } if (!includeNotFound) { query = query.And(Query.NE(FieldNames.Type, "404")); } return(Find <PersistentEvent>(FindOptionsExtensions.WithPaging(new MultiOptions().WithProjectId(projectId).WithQuery(query), paging).WithSort(SortBy.Descending(FieldNames.Date_UTC)))); }
public virtual IMongoQuery GetQuery(Func <string, BsonValue> getIdValue = null) { if (getIdValue == null) { getIdValue = id => new BsonObjectId(new ObjectId(id)); } IMongoQuery query = Query; if (Ids.Count > 0) { query = query.And(MongoDB.Driver.Builders.Query.In(CommonFieldNames.Id, Ids.Select(id => getIdValue(id)))); } if (OrganizationIds.Count > 0) { query = query.And(MongoDB.Driver.Builders.Query.In(CommonFieldNames.OrganizationId, OrganizationIds.Select(id => new BsonObjectId(new ObjectId(id))))); } if (ProjectIds.Count > 0) { query = query.And(MongoDB.Driver.Builders.Query.In(CommonFieldNames.ProjectId, ProjectIds.Select(id => new BsonObjectId(new ObjectId(id))))); } if (StackIds.Count > 0) { query = query.And(MongoDB.Driver.Builders.Query.In(CommonFieldNames.StackId, StackIds.Select(id => new BsonObjectId(new ObjectId(id))))); } return(query); }
public static IMongoQuery GetMongoQuery(this QueryOptions options, Func <string, BsonValue> getIdValue = null) { if (getIdValue == null) { getIdValue = id => new BsonObjectId(new ObjectId(id)); } var mongoOptions = options as MongoOptions; IMongoQuery query = mongoOptions != null ? mongoOptions.Query : Query.Null; if (options.Ids.Count > 0) { if (options.Ids.Count == 1) { query = query.And(Query.EQ(CommonFieldNames.Id, getIdValue(options.Ids.First()))); } else { query = query.And(Query.In(CommonFieldNames.Id, options.Ids.Select(id => getIdValue(id)))); } } if (options.OrganizationIds.Count > 0) { if (options.OrganizationIds.Count == 1) { query = query.And(Query.EQ(CommonFieldNames.OrganizationId, new BsonObjectId(new ObjectId(options.OrganizationIds.First())))); } else { query = query.And(Query.In(CommonFieldNames.OrganizationId, options.OrganizationIds.Select(id => new BsonObjectId(new ObjectId(id))))); } } if (options.ProjectIds.Count > 0) { if (options.ProjectIds.Count == 1) { query = query.And(Query.EQ(CommonFieldNames.ProjectId, new BsonObjectId(new ObjectId(options.ProjectIds.First())))); } else { query = query.And(Query.In(CommonFieldNames.ProjectId, options.ProjectIds.Select(id => new BsonObjectId(new ObjectId(id))))); } } if (options.StackIds.Count > 0) { if (options.StackIds.Count == 1) { query = query.And(Query.EQ(CommonFieldNames.StackId, new BsonObjectId(new ObjectId(options.StackIds.First())))); } else { query = query.And(Query.In(CommonFieldNames.StackId, options.StackIds.Select(id => new BsonObjectId(new ObjectId(id))))); } } return(query); }
public ICollection <PersistentEvent> GetByStackIdOccurrenceDate(string stackId, DateTime utcStart, DateTime utcEnd, PagingOptions paging) { IMongoQuery query = Query.Null; if (utcStart != DateTime.MinValue) { query = query.And(Query.GTE(FieldNames.Date_UTC, utcStart.Ticks)); } if (utcEnd != DateTime.MaxValue) { query = query.And(Query.LTE(FieldNames.Date_UTC, utcEnd.Ticks)); } return(Find <PersistentEvent>(FindOptionsExtensions.WithPaging(new MultiOptions().WithStackId(stackId).WithQuery(query), paging).WithSort(SortBy.Descending(FieldNames.Date_UTC)))); }
public static List<供应商> 抽选供应商(int count, IMongoQuery conditions, IEnumerable<long> selected, IEnumerable<long> avoid) { var ret = new List<供应商>(count); var rnd = new Random(); conditions = conditions.And(Query<供应商>.EQ(o => o.审核数据.审核状态, 审核状态.审核通过)); if (null != selected && 0 != selected.Count()) { var q = Query.NotIn("_id", new BsonArray(selected)); conditions = Query.And(conditions, q); } if (null != avoid && 0 != avoid.Count()) { var q = Query.NotIn("_id", new BsonArray(avoid)); conditions = Query.And(conditions, q); } int total = (int)Mongo.计数<供应商>(0, 0, conditions); if (total < count) return new List<供应商>(); var r = Mongo.查询<供应商>(0, 0, conditions); var ns = new HashSet<int>(); for (int i = 0; i < count; i++) { int n; do { n = rnd.Next(total); } while (ns.Contains(n)); ret.Add(r.ElementAt(n)); ns.Add(n); } return ret; }
public override IMongoQuery GetQuery(Func <string, BsonValue> getIdValue = null) { IMongoQuery query = base.GetQuery(getIdValue); if (getIdValue == null) { getIdValue = id => new BsonObjectId(new ObjectId(id)); } if (Page.HasValue) { return(query); } if (!String.IsNullOrEmpty(BeforeValue) && BeforeQuery == null) { BeforeQuery = MongoDB.Driver.Builders.Query.LT(CommonFieldNames.Id, getIdValue(BeforeValue)); } if (!String.IsNullOrEmpty(AfterValue) && AfterQuery == null) { AfterQuery = MongoDB.Driver.Builders.Query.LT(CommonFieldNames.Id, getIdValue(AfterValue)); } query = query.And(BeforeQuery, AfterQuery); return(query); }