Class PagedSearch<T, TProjection>
Represents an aggregation query that retrieves results with easy paging support.
Inherited Members
Namespace: MongoDB.Entities
Assembly: MongoDB.Entities.dll
Syntax
public class PagedSearch<T, TProjection>
where T : IEntity
Type Parameters
Name | Description |
---|---|
T | Any class that implements IEntity |
TProjection | The type you'd like to project the results to. |
Methods
ExecuteAsync(CancellationToken)
Run the aggregation search command in MongoDB server and get a page of results and total + page count
Declaration
public async Task<(IReadOnlyList<TProjection> Results, long TotalCount, int PageCount)> ExecuteAsync(CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellation | An optional cancellation token |
Returns
Type | Description |
---|---|
Task<(T1 Item1, T2 Item2, T3 Item3)<IReadOnlyList<TProjection>, Int64, Int32>> |
IgnoreGlobalFilters()
Specify that this operation should ignore any global filters
Declaration
public PagedSearch<T, TProjection> IgnoreGlobalFilters()
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Match(FilterDefinition<T>)
Specify the matching criteria with a filter definition
Declaration
public PagedSearch<T, TProjection> Match(FilterDefinition<T> filterDefinition)
Parameters
Type | Name | Description |
---|---|---|
FilterDefinition<T> | filterDefinition | A filter definition |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Match(Search, String, Boolean, Boolean, String)
Specify a search term to find results from the text index of this particular collection.
TIP: Make sure to define a text index with DB.Index<T>() before searching
Declaration
public PagedSearch<T, TProjection> Match(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string language = null)
Parameters
Type | Name | Description |
---|---|---|
Search | searchType | The type of text matching to do |
String | searchTerm | The search term |
Boolean | caseSensitive | Case sensitivity of the search (optional) |
Boolean | diacriticSensitive | Diacritic sensitivity of the search (optional) |
String | language | The language for the search (optional) |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Match(Template)
Specify the matching criteria with a template
Declaration
public PagedSearch<T, TProjection> Match(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template with a find query |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Specify the matching criteria with a filter expression
Declaration
public PagedSearch<T, TProjection> Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> filter)
Parameters
Type | Name | Description |
---|---|---|
Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> | filter | f => f.Eq(x => x.Prop, Value) & f.Gt(x => x.Prop, Value) |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Match(Expression<Func<T, Boolean>>)
Specify the matching criteria with a lambda expression
Declaration
public PagedSearch<T, TProjection> Match(Expression<Func<T, bool>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Boolean>> | expression | x => x.Property == Value |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Match(Expression<Func<T, Object>>, Coordinates2D, Nullable<Double>, Nullable<Double>)
Specify criteria for matching entities based on GeoSpatial data (longitude & latitude)
TIP: Make sure to define a Geo2DSphere index with DB.Index<T>() before searching
Note: DB.FluentGeoNear() supports more advanced options
Declaration
public PagedSearch<T, TProjection> Match(Expression<Func<T, object>> coordinatesProperty, Coordinates2D nearCoordinates, double? maxDistance = null, double? minDistance = null)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | coordinatesProperty | The property where 2DCoordinates are stored |
Coordinates2D | nearCoordinates | The search point |
Nullable<Double> | maxDistance | Maximum distance in meters from the search point |
Nullable<Double> | minDistance | Minimum distance in meters from the search point |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
MatchExpression(Template)
Specify the matching criteria with a Template
Declaration
public PagedSearch<T, TProjection> MatchExpression(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template object |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
MatchExpression(String)
Specify the matching criteria with an aggregation expression (i.e. $expr)
Declaration
public PagedSearch<T, TProjection> MatchExpression(string expression)
Parameters
Type | Name | Description |
---|---|---|
String | expression | { $gt: ['$Property1', '$Property2'] } |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
MatchString(String)
Specify the matching criteria with a JSON string
Declaration
public PagedSearch<T, TProjection> MatchString(string jsonString)
Parameters
Type | Name | Description |
---|---|---|
String | jsonString | { Title : 'The Power Of Now' } |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Option(Action<AggregateOptions>)
Specify an option for this find command (use multiple times if needed)
Declaration
public PagedSearch<T, TProjection> Option(Action<AggregateOptions> option)
Parameters
Type | Name | Description |
---|---|---|
Action<AggregateOptions> | option | x => x.OptionName = OptionValue |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
PageNumber(Int32)
Specify the page number to get
Declaration
public PagedSearch<T, TProjection> PageNumber(int pageNumber)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pageNumber | The page number |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
PageSize(Int32)
Specify the number of items per page
Declaration
public PagedSearch<T, TProjection> PageSize(int pageSize)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pageSize | The size of a page |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>>)
Specify how to project the results using a projection expression
Declaration
public PagedSearch<T, TProjection> Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>> projection)
Parameters
Type | Name | Description |
---|---|---|
Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>> | projection | p => p.Include("Prop1").Exclude("Prop2") |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Project(Expression<Func<T, TProjection>>)
Specify how to project the results using a lambda expression
Declaration
public PagedSearch<T, TProjection> Project(Expression<Func<T, TProjection>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TProjection>> | expression | x => new Test { PropName = x.Prop } |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
ProjectExcluding(Expression<Func<T, Object>>)
Specify how to project the results using an exclusion projection expression.
Declaration
public PagedSearch<T, TProjection> ProjectExcluding(Expression<Func<T, object>> exclusion)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | exclusion | x => new { x.PropToExclude, x.AnotherPropToExclude } |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Sort(Func<SortDefinitionBuilder<T>, SortDefinition<T>>)
Specify how to sort using a sort expression
Declaration
public PagedSearch<T, TProjection> Sort(Func<SortDefinitionBuilder<T>, SortDefinition<T>> sortFunction)
Parameters
Type | Name | Description |
---|---|---|
Func<SortDefinitionBuilder<T>, SortDefinition<T>> | sortFunction | s => s.Ascending("Prop1").MetaTextScore("Prop2") |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Sort(Expression<Func<T, Object>>, Order)
Specify which property and order to use for sorting (use multiple times if needed)
Declaration
public PagedSearch<T, TProjection> Sort(Expression<Func<T, object>> propertyToSortBy, Order sortOrder)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | propertyToSortBy | x => x.Prop |
Order | sortOrder | The sort order |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
SortByTextScore()
Sort the results of a text search by the MetaTextScore
TIP: Use this method after .Project() if you need to do a projection also
Declaration
public PagedSearch<T, TProjection> SortByTextScore()
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
SortByTextScore(Expression<Func<T, Object>>)
Sort the results of a text search by the MetaTextScore and get back the score as well
TIP: Use this method after .Project() if you need to do a projection also
Declaration
public PagedSearch<T, TProjection> SortByTextScore(Expression<Func<T, object>> scoreProperty)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | scoreProperty | x => x.TextScoreProp |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
WithFluent<TFluent>(TFluent)
Begins the paged search aggregation pipeline with the provided fluent pipeline.
TIP: This method must be first in the chain and it cannot be used with .Match()
Declaration
public PagedSearch<T, TProjection> WithFluent<TFluent>(TFluent fluentPipeline)
where TFluent : IAggregateFluent<T>
Parameters
Type | Name | Description |
---|---|---|
TFluent | fluentPipeline | The input IAggregateFluent pipeline |
Returns
Type | Description |
---|---|
PagedSearch<T, TProjection> |
Type Parameters
Name | Description |
---|---|
TFluent | The type of the input pipeline |