private async Task <List <MongoContentEntity> > FindContentsAsync(ClrQuery query, FilterDefinition <MongoContentEntity> filter) { if (query.Skip > 0 && !IsSatisfiedByIndex(query)) { var projection = Projection.Include("_id"); foreach (var field in query.GetAllFields()) { projection = projection.Include(field); } var joined = await Collection.Aggregate() .Match(filter) .Project <IdOnly>(projection) .QuerySort(query) .QuerySkip(query) .QueryLimit(query) .Lookup <IdOnly, MongoContentEntity, IdOnly>(Collection, x => x.Id, x => x.DocumentId, x => x.Joined) .ToListAsync(); return(joined.Select(x => x.Joined[0]).ToList()); } var result = Collection.Find(filter) .QuerySort(query) .QueryLimit(query) .QuerySkip(query) .ToListAsync(); return(await result); }
public void Should_add_fields_from_sorting() { var query = new ClrQuery { Sort = new List <SortNode> { new SortNode("field1", SortOrder.Ascending), new SortNode("field1", SortOrder.Ascending), new SortNode("field2", SortOrder.Ascending) } }; var fields = query.GetAllFields(); var expected = new HashSet <string> { "field1", "field2" }; Assert.Equal(expected, fields); }
public void Should_add_fields_from_filters() { var query = new ClrQuery { Filter = ClrFilter.And( ClrFilter.Not( ClrFilter.Eq("field1", 1)), ClrFilter.Or( ClrFilter.Eq("field2", 2), ClrFilter.Eq("field2", 4))) }; var fields = query.GetAllFields(); var expected = new HashSet <string> { "field1", "field2" }; Assert.Equal(expected, fields); }