/// <summary> /// Appends a $bucketAuto stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="groupBy">The expression providing the value to group by.</param> /// <param name="buckets">The number of buckets.</param> /// <param name="options">The options (optional).</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <AggregateBucketAutoResult <TValue> > BucketAuto <TResult, TValue>( this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TValue> > groupBy, int buckets, AggregateBucketAutoOptions options = null) { Ensure.IsNotNull(aggregate, nameof(aggregate)); Ensure.IsNotNull(groupBy, nameof(groupBy)); var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions); return(aggregate.BucketAuto(groupByDefinition, buckets, options)); }
/// <summary> /// Appends a $bucket stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="groupBy">The expression providing the value to group by.</param> /// <param name="boundaries">The bucket boundaries.</param> /// <param name="options">The options.</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <AggregateBucketResult <TValue> > Bucket <TResult, TValue>( this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TValue> > groupBy, IEnumerable <TValue> boundaries, AggregateBucketOptions <TValue> options = null) { Ensure.IsNotNull(aggregate, nameof(aggregate)); Ensure.IsNotNull(groupBy, nameof(groupBy)); Ensure.IsNotNull(boundaries, nameof(boundaries)); var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions); return(aggregate.Bucket(groupByDefinition, boundaries, options)); }
/// <summary> /// Appends a $bucketAuto stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TNewResult">The type of the new result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="groupBy">The expression providing the value to group by.</param> /// <param name="buckets">The number of buckets.</param> /// <param name="output">The output projection.</param> /// <param name="options">The options (optional).</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <TNewResult> BucketAuto <TResult, TValue, TNewResult>( this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TValue> > groupBy, int buckets, Expression <Func <IGrouping <TValue, TResult>, TNewResult> > output, AggregateBucketAutoOptions options = null) { Ensure.IsNotNull(aggregate, nameof(aggregate)); Ensure.IsNotNull(groupBy, nameof(groupBy)); Ensure.IsNotNull(output, nameof(output)); var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions); var outputDefinition = new ExpressionBucketOutputProjection <TResult, TValue, TNewResult>(x => default(TValue), output, aggregate.Options.TranslationOptions); return(aggregate.BucketAuto(groupByDefinition, buckets, outputDefinition, options)); }
/// <summary> /// Appends a $bucket stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TNewResult">The type of the new result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="groupBy">The expression providing the value to group by.</param> /// <param name="boundaries">The bucket boundaries.</param> /// <param name="output">The output projection.</param> /// <param name="defaultBucket">The default bucket (optional).</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <TNewResult> Bucket <TResult, TValue, TNewResult>( this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TValue> > groupBy, IEnumerable <TValue> boundaries, Expression <Func <IGrouping <TValue, TResult>, TNewResult> > output, Optional <TValue> defaultBucket = default(Optional <TValue>)) { Ensure.IsNotNull(aggregate, nameof(aggregate)); Ensure.IsNotNull(groupBy, nameof(groupBy)); Ensure.IsNotNull(boundaries, nameof(boundaries)); var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions); var outputDefinition = new ExpressionBucketOutputProjection <TResult, TValue, TNewResult>(x => default(TValue), output, aggregate.Options.TranslationOptions); return(aggregate.Bucket(groupByDefinition, boundaries, outputDefinition, defaultBucket)); }
/// <summary> /// Appends a $graphLookup stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TNewResult">The type of the new result (must be same as TResult with an additional as field).</typeparam> /// <typeparam name="TFrom">The type of the from documents.</typeparam> /// <typeparam name="TConnect">The type of the connect field.</typeparam> /// <typeparam name="TConnectFrom">The type of the connect from field (must be either TConnect or a type that implements IEnumerable{TConnect}).</typeparam> /// <typeparam name="TStartWith">The type of the start with expression (must be either TConnect or a type that implements IEnumerable{TConnect}).</typeparam> /// <typeparam name="TAsEnumerable">The type of the enumerable as field.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="from">The from collection.</param> /// <param name="connectFromField">The connect from field.</param> /// <param name="connectToField">The connect to field.</param> /// <param name="startWith">The start with value.</param> /// <param name="as">The as field.</param> /// <param name="options">The options.</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <TNewResult> GraphLookup <TResult, TNewResult, TFrom, TConnect, TConnectFrom, TStartWith, TAsEnumerable>( this IAggregateFluent <TResult> aggregate, IMongoCollection <TFrom> from, Expression <Func <TFrom, TConnectFrom> > connectFromField, Expression <Func <TFrom, TConnect> > connectToField, Expression <Func <TResult, TStartWith> > startWith, Expression <Func <TNewResult, TAsEnumerable> > @as, AggregateGraphLookupOptions <TNewResult, TFrom, TConnect, TConnectFrom, TStartWith, TFrom, TAsEnumerable> options = null) where TAsEnumerable : IEnumerable <TFrom> { Ensure.IsNotNull(aggregate, nameof(aggregate)); Ensure.IsNotNull(from, nameof(from)); Ensure.IsNotNull(connectFromField, nameof(connectFromField)); Ensure.IsNotNull(connectToField, nameof(connectToField)); Ensure.IsNotNull(startWith, nameof(startWith)); Ensure.IsNotNull(@as, nameof(@as)); var connectFromFieldDefinition = new ExpressionFieldDefinition <TFrom, TConnectFrom>(connectFromField); var connectToFieldDefinition = new ExpressionFieldDefinition <TFrom, TConnect>(connectToField); var startWithDefinition = new ExpressionAggregateExpressionDefinition <TResult, TStartWith>(startWith, aggregate.Options.TranslationOptions); var asDefinition = new ExpressionFieldDefinition <TNewResult, TAsEnumerable>(@as); return(aggregate.GraphLookup(from, connectFromFieldDefinition, connectToFieldDefinition, startWithDefinition, asDefinition, options)); }