public async Task <IEnumerable <Job> > QueryFor(JobQuery query) { var mongoQuery = _jobs.Find(query.BuildFilters()); if (query.Limit.HasValue) { mongoQuery = mongoQuery.Limit(query.Limit.Value); } if (query.Skip.HasValue) { mongoQuery = mongoQuery.Skip(query.Skip.Value); } if (!string.IsNullOrWhiteSpace(query.AdhocSort)) { BsonDocument bsonDocumentSort; try { bsonDocumentSort = BsonSerializer.Deserialize <BsonDocument>(query.AdhocSort); } catch (Exception ex) { throw new InvalidOperationException($"Invalid adhocSort ({query.AdhocSort})", ex); } mongoQuery = mongoQuery.Sort(bsonDocumentSort); } return(await mongoQuery.ToListAsync().ConfigureAwait(false)); }
public async Task <IEnumerable <Job> > QueryFor(JobQuery query) { var mongoQuery = _jobs.Find(query.BuildFilters()); if (query.Limit.HasValue) { mongoQuery = mongoQuery.Limit(query.Limit.Value); } return(await mongoQuery.ToListAsync().ConfigureAwait(false)); }
public async Task <long> QueryCount(JobQuery query) { return(await _jobs.Find(query.BuildFilters()).CountAsync().ConfigureAwait(false)); }