| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177 |
- /* Copyright 2016 MongoDB Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using MongoDB.Bson;
- using MongoDB.Bson.Serialization;
- using MongoDB.Driver.Core.Misc;
- namespace MongoDB.Driver
- {
- /// <summary>
- /// Extension methods for adding stages to a pipeline.
- /// </summary>
- public static class PipelineDefinitionBuilder
- {
- /// <summary>
- /// Appends a stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="stage">The stage.</param>
- /// <param name="outputSerializer">The output serializer.</param>
- /// <returns>A new pipeline with an additional stage.</returns>
- public static PipelineDefinition<TInput, TOutput> AppendStage<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- PipelineStageDefinition<TIntermediate, TOutput> stage,
- IBsonSerializer<TOutput> outputSerializer = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- Ensure.IsNotNull(stage, nameof(stage));
- return new AppendedStagePipelineDefinition<TInput, TIntermediate, TOutput>(pipeline, stage, outputSerializer);
- }
- /// <summary>
- /// Changes the output type of the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="outputSerializer">The output serializer.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> As<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IBsonSerializer<TOutput> outputSerializer = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return new ReplaceOutputSerializerPipelineDefinition<TInput, TIntermediate, TOutput>(pipeline, outputSerializer);
- }
- /// <summary>
- /// Appends a $bucket stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="boundaries">The boundaries.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateBucketResult<TValue>> Bucket<TInput, TIntermediate, TValue>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- AggregateExpressionDefinition<TIntermediate, TValue> groupBy,
- IEnumerable<TValue> boundaries,
- AggregateBucketOptions<TValue> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Bucket(groupBy, boundaries, options));
- }
- /// <summary>
- /// Appends a $bucket stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="boundaries">The boundaries.</param>
- /// <param name="output">The output projection.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Bucket<TInput, TIntermediate, TValue, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- AggregateExpressionDefinition<TIntermediate, TValue> groupBy,
- IEnumerable<TValue> boundaries,
- ProjectionDefinition<TIntermediate, TOutput> output,
- AggregateBucketOptions<TValue> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Bucket(groupBy, boundaries, output, options));
- }
- /// <summary>
- /// Appends a $bucket stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="boundaries">The boundaries.</param>
- /// <param name="options">The options.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateBucketResult<TValue>> Bucket<TInput, TIntermediate, TValue>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TValue>> groupBy,
- IEnumerable<TValue> boundaries,
- AggregateBucketOptions<TValue> options = null,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Bucket(groupBy, boundaries, options, translationOptions));
- }
- /// <summary>
- /// Appends a $bucket stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="boundaries">The boundaries.</param>
- /// <param name="output">The output projection.</param>
- /// <param name="options">The options.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Bucket<TInput, TIntermediate, TValue, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TValue>> groupBy,
- IEnumerable<TValue> boundaries,
- Expression<Func<IGrouping<TValue, TIntermediate>, TOutput>> output,
- AggregateBucketOptions<TValue> options = null,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Bucket(groupBy, boundaries, output, options, translationOptions));
- }
- /// <summary>
- /// Appends a $bucketAuto stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="buckets">The number of buckets.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateBucketAutoResult<TValue>> BucketAuto<TInput, TIntermediate, TValue>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- AggregateExpressionDefinition<TIntermediate, TValue> groupBy,
- int buckets,
- AggregateBucketAutoOptions options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.BucketAuto(groupBy, buckets, options));
- }
- /// <summary>
- /// Appends a $bucketAuto stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="buckets">The number of buckets.</param>
- /// <param name="output">The output projection.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> BucketAuto<TInput, TIntermediate, TValue, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- AggregateExpressionDefinition<TIntermediate, TValue> groupBy,
- int buckets,
- ProjectionDefinition<TIntermediate, TOutput> output,
- AggregateBucketAutoOptions options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.BucketAuto(groupBy, buckets, output, options));
- }
- /// <summary>
- /// Appends a $bucketAuto stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the value.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="buckets">The number of buckets.</param>
- /// <param name="options">The options (optional).</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateBucketAutoResult<TValue>> BucketAuto<TInput, TIntermediate, TValue>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TValue>> groupBy,
- int buckets,
- AggregateBucketAutoOptions options = null,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.BucketAuto(groupBy, buckets, options, translationOptions));
- }
- /// <summary>
- /// Appends a $bucketAuto stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the value.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="groupBy">The group by expression.</param>
- /// <param name="buckets">The number of buckets.</param>
- /// <param name="output">The output projection.</param>
- /// <param name="options">The options (optional).</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> BucketAuto<TInput, TIntermediate, TValue, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TValue>> groupBy,
- int buckets,
- Expression<Func<IGrouping<TValue, TIntermediate>, TOutput>> output,
- AggregateBucketAutoOptions options = null,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.BucketAuto(groupBy, buckets, output, options, translationOptions));
- }
- /// <summary>
- /// Appends a $count stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateCountResult> Count<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Count<TIntermediate>());
- }
- /// <summary>
- /// Appends a $facet stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="facets">The facets.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Facet<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IEnumerable<AggregateFacet<TIntermediate>> facets,
- AggregateFacetOptions<TOutput> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Facet(facets, options));
- }
- /// <summary>
- /// Appends a $facet stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="facets">The facets.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateFacetResults> Facet<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IEnumerable<AggregateFacet<TIntermediate>> facets)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Facet(facets));
- }
- /// <summary>
- /// Appends a $facet stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="facets">The facets.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateFacetResults> Facet<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- params AggregateFacet<TIntermediate>[] facets)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Facet(facets));
- }
- /// <summary>
- /// Appends a $facet stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="facets">The facets.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Facet<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- params AggregateFacet<TIntermediate>[] facets)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Facet<TIntermediate, TOutput>(facets));
- }
- /// <summary>
- /// Used to start creating a pipeline for {TInput} documents.
- /// </summary>
- /// <typeparam name="TInput">The type of the output.</typeparam>
- /// <param name="inputSerializer">The inputSerializer serializer.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TInput> For<TInput>(IBsonSerializer<TInput> inputSerializer = null)
- {
- return new EmptyPipelineDefinition<TInput>(inputSerializer);
- }
- /// <summary>
- /// Appends a $graphLookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TFrom">The type of the from documents.</typeparam>
- /// <typeparam name="TConnectFrom">The type of the connect from field (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TConnectTo">The type of the connect to field.</typeparam>
- /// <typeparam name="TStartWith">The type of the start with expression (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TAsElement">The type of the as field elements.</typeparam>
- /// <typeparam name="TAs">The type of the as field.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</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="depthField">The depth field.</param>
- /// <param name="options">The options.</param>
- /// <returns>The fluent aggregate interface.</returns>
- public static PipelineDefinition<TInput, TOutput> GraphLookup<TInput, TIntermediate, TFrom, TConnectFrom, TConnectTo, TStartWith, TAsElement, TAs, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TFrom> from,
- FieldDefinition<TFrom, TConnectFrom> connectFromField,
- FieldDefinition<TFrom, TConnectTo> connectToField,
- AggregateExpressionDefinition<TIntermediate, TStartWith> startWith,
- FieldDefinition<TOutput, TAs> @as,
- FieldDefinition<TAsElement, int> depthField,
- AggregateGraphLookupOptions<TFrom, TAsElement, TOutput> options = null)
- where TAs : IEnumerable<TAsElement>
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, depthField, options));
- }
- /// <summary>
- /// Appends a $graphLookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TFrom">The type of the from documents.</typeparam>
- /// <typeparam name="TConnectFrom">The type of the connect from field (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TConnectTo">The type of the connect to field.</typeparam>
- /// <typeparam name="TStartWith">The type of the start with expression (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TAs">The type of the as field.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</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 stage.</returns>
- public static PipelineDefinition<TInput, TOutput> GraphLookup<TInput, TIntermediate, TFrom, TConnectFrom, TConnectTo, TStartWith, TAs, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TFrom> from,
- FieldDefinition<TFrom, TConnectFrom> connectFromField,
- FieldDefinition<TFrom, TConnectTo> connectToField,
- AggregateExpressionDefinition<TIntermediate, TStartWith> startWith,
- FieldDefinition<TOutput, TAs> @as,
- AggregateGraphLookupOptions<TFrom, TFrom, TOutput> options = null)
- where TAs : IEnumerable<TFrom>
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, options));
- }
- /// <summary>
- /// Appends a $graphLookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TFrom">The type of the from documents.</typeparam>
- /// <param name="pipeline">The pipeline.</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="depthField">The depth field.</param>
- /// <returns>The fluent aggregate interface.</returns>
- public static PipelineDefinition<TInput, BsonDocument> GraphLookup<TInput, TIntermediate, TFrom>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TFrom> from,
- FieldDefinition<TFrom, BsonValue> connectFromField,
- FieldDefinition<TFrom, BsonValue> connectToField,
- AggregateExpressionDefinition<TIntermediate, BsonValue> startWith,
- FieldDefinition<BsonDocument, IEnumerable<BsonDocument>> @as,
- FieldDefinition<BsonDocument, int> depthField = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, depthField));
- }
- /// <summary>
- /// Appends a $graphLookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TFrom">The type of the from documents.</typeparam>
- /// <typeparam name="TConnectFrom">The type of the connect from field (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TConnectTo">The type of the connect to field.</typeparam>
- /// <typeparam name="TStartWith">The type of the start with expression (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TAs">The type of the as field.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</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>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>The stage.</returns>
- public static PipelineDefinition<TInput, TOutput> GraphLookup<TInput, TIntermediate, TFrom, TConnectFrom, TConnectTo, TStartWith, TAs, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TFrom> from,
- Expression<Func<TFrom, TConnectFrom>> connectFromField,
- Expression<Func<TFrom, TConnectTo>> connectToField,
- Expression<Func<TIntermediate, TStartWith>> startWith,
- Expression<Func<TOutput, TAs>> @as,
- AggregateGraphLookupOptions<TFrom, TFrom, TOutput> options = null,
- ExpressionTranslationOptions translationOptions = null)
- where TAs : IEnumerable<TFrom>
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, options, translationOptions));
- }
- /// <summary>
- /// Appends a $graphLookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TFrom">The type of the from documents.</typeparam>
- /// <typeparam name="TConnectFrom">The type of the connect from field (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TConnectTo">The type of the connect to field.</typeparam>
- /// <typeparam name="TStartWith">The type of the start with expression (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
- /// <typeparam name="TAsElement">The type of the as field elements.</typeparam>
- /// <typeparam name="TAs">The type of the as field.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</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="depthField">The depth field.</param>
- /// <param name="options">The options.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>The stage.</returns>
- public static PipelineDefinition<TInput, TOutput> GraphLookup<TInput, TIntermediate, TFrom, TConnectFrom, TConnectTo, TStartWith, TAsElement, TAs, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TFrom> from,
- Expression<Func<TFrom, TConnectFrom>> connectFromField,
- Expression<Func<TFrom, TConnectTo>> connectToField,
- Expression<Func<TIntermediate, TStartWith>> startWith,
- Expression<Func<TOutput, TAs>> @as,
- Expression<Func<TAsElement, int>> depthField,
- AggregateGraphLookupOptions<TFrom, TAsElement, TOutput> options = null,
- ExpressionTranslationOptions translationOptions = null)
- where TAs : IEnumerable<TAsElement>
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, depthField, options, translationOptions));
- }
- /// <summary>
- /// Appends a $group stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="group">The group projection.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Group<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- ProjectionDefinition<TIntermediate, TOutput> group)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Group(group));
- }
- /// <summary>
- /// Appends a group stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="group">The group projection.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, BsonDocument> Group<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- ProjectionDefinition<TIntermediate, BsonDocument> group)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Group(group));
- }
- /// <summary>
- /// Appends a group stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TKey">The type of the key.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="id">The id.</param>
- /// <param name="group">The group projection.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Group<TInput, TIntermediate, TKey, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TKey>> id,
- Expression<Func<IGrouping<TKey, TIntermediate>, TOutput>> group,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Group(id, group, translationOptions));
- }
- /// <summary>
- /// Appends a $limit stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="limit">The limit.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Limit<TInput, TOutput>(
- this PipelineDefinition<TInput, TOutput> pipeline,
- int limit)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Limit<TOutput>(limit));
- }
- /// <summary>
- /// Appends a $lookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TForeignDocument">The type of the foreign collection documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="foreignCollection">The foreign collection.</param>
- /// <param name="localField">The local field.</param>
- /// <param name="foreignField">The foreign field.</param>
- /// <param name="as">The "as" field.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Lookup<TInput, TIntermediate, TForeignDocument, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TForeignDocument> foreignCollection,
- FieldDefinition<TIntermediate> localField,
- FieldDefinition<TForeignDocument> foreignField,
- FieldDefinition<TOutput> @as,
- AggregateLookupOptions<TForeignDocument, TOutput> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Lookup(foreignCollection, localField, foreignField, @as, options));
- }
- /// <summary>
- /// Appends a lookup stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TForeignDocument">The type of the foreign collection documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="foreignCollection">The foreign collection.</param>
- /// <param name="localField">The local field.</param>
- /// <param name="foreignField">The foreign field.</param>
- /// <param name="as">The "as" field.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Lookup<TInput, TIntermediate, TForeignDocument, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TForeignDocument> foreignCollection,
- Expression<Func<TIntermediate, object>> localField,
- Expression<Func<TForeignDocument, object>> foreignField,
- Expression<Func<TOutput, object>> @as,
- AggregateLookupOptions<TForeignDocument, TOutput> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Lookup(foreignCollection, localField, foreignField, @as, options));
- }
- /// <summary>
- /// Appends a $match stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="filter">The filter.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Match<TInput, TOutput>(
- this PipelineDefinition<TInput, TOutput> pipeline,
- FilterDefinition<TOutput> filter)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Match(filter));
- }
- /// <summary>
- /// Appends a match stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="filter">The filter.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Match<TInput, TOutput>(
- this PipelineDefinition<TInput, TOutput> pipeline,
- Expression<Func<TOutput, bool>> filter)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Match(filter));
- }
- /// <summary>
- /// Appends a $match stage to the pipeline to select documents of a certain type.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="outputSerializer">The output serializer.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- /// <exception cref="System.NotSupportedException"></exception>
- public static PipelineDefinition<TInput, TOutput> OfType<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IBsonSerializer<TOutput> outputSerializer = null)
- where TOutput : TIntermediate
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.OfType<TIntermediate, TOutput>(outputSerializer));
- }
- /// <summary>
- /// Appends a $out stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="outputCollection">The output collection.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- /// <exception cref="System.NotSupportedException"></exception>
- public static PipelineDefinition<TInput, TOutput> Out<TInput, TOutput>(
- this PipelineDefinition<TInput, TOutput> pipeline,
- IMongoCollection<TOutput> outputCollection)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Out<TOutput>(outputCollection));
- }
- /// <summary>
- /// Appends a $project stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="projection">The projection.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- /// <exception cref="System.NotSupportedException"></exception>
- public static PipelineDefinition<TInput, TOutput> Project<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- ProjectionDefinition<TIntermediate, TOutput> projection)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Project(projection));
- }
- /// <summary>
- /// Appends a project stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="projection">The projection.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, BsonDocument> Project<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- ProjectionDefinition<TIntermediate, BsonDocument> projection)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Project(projection));
- }
- /// <summary>
- /// Appends a project stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="projection">The projection.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Project<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TOutput>> projection,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Project(projection, translationOptions));
- }
- /// <summary>
- /// Appends a $replaceRoot stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="newRoot">The new root.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> ReplaceRoot<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- AggregateExpressionDefinition<TIntermediate, TOutput> newRoot)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.ReplaceRoot(newRoot));
- }
- /// <summary>
- /// Appends a $replaceRoot stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="newRoot">The new root.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> ReplaceRoot<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TOutput>> newRoot,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.ReplaceRoot(newRoot, translationOptions));
- }
- /// <summary>
- /// Appends a $skip stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="skip">The number of documents to skip.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Skip<TInput, TOutput>(
- this PipelineDefinition<TInput, TOutput> pipeline,
- int skip)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Skip<TOutput>(skip));
- }
- /// <summary>
- /// Appends a $sort stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="sort">The sort definition.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Sort<TInput, TOutput>(
- this PipelineDefinition<TInput, TOutput> pipeline,
- SortDefinition<TOutput> sort)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Sort(sort));
- }
- /// <summary>
- /// Appends a $sortByCount stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="value">The value expression.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateSortByCountResult<TValue>> SortByCount<TInput, TIntermediate, TValue>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- AggregateExpressionDefinition<TIntermediate, TValue> value)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.SortByCount(value));
- }
- /// <summary>
- /// Appends a sortByCount stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TValue">The type of the values.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="value">The value expression.</param>
- /// <param name="translationOptions">The translation options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, AggregateSortByCountResult<TValue>> SortByCount<TInput, TIntermediate, TValue>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, TValue>> value,
- ExpressionTranslationOptions translationOptions = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.SortByCount(value, translationOptions));
- }
- /// <summary>
- /// Appends an $unwind stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="field">The field.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// A new pipeline with an additional stage.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Unwind<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- FieldDefinition<TIntermediate> field,
- AggregateUnwindOptions<TOutput> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Unwind(field, options));
- }
- /// <summary>
- /// Appends an unwind stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="field">The field to unwind.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, BsonDocument> Unwind<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- FieldDefinition<TIntermediate> field,
- AggregateUnwindOptions<BsonDocument> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Unwind(field, options));
- }
- /// <summary>
- /// Appends an unwind stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="field">The field to unwind.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, BsonDocument> Unwind<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, object>> field,
- AggregateUnwindOptions<BsonDocument> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Unwind(field, options));
- }
- /// <summary>
- /// Appends an unwind stage to the pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="field">The field to unwind.</param>
- /// <param name="options">The options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, TOutput> Unwind<TInput, TIntermediate, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- Expression<Func<TIntermediate, object>> field,
- AggregateUnwindOptions<TOutput> options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Unwind(field, options));
- }
- }
- /// <summary>
- /// Represents a pipeline consisting of an existing pipeline with one additional stage appended.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- public sealed class AppendedStagePipelineDefinition<TInput, TIntermediate, TOutput> : PipelineDefinition<TInput, TOutput>
- {
- private readonly IBsonSerializer<TOutput> _outputSerializer;
- private readonly PipelineDefinition<TInput, TIntermediate> _pipeline;
- private readonly PipelineStageDefinition<TIntermediate, TOutput> _stage;
- /// <summary>
- /// Initializes a new instance of the <see cref="AppendedStagePipelineDefinition{TInput, TIntermediate, TOutput}" /> class.
- /// </summary>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="stage">The stage.</param>
- /// <param name="outputSerializer">The output serializer.</param>
- public AppendedStagePipelineDefinition(
- PipelineDefinition<TInput, TIntermediate> pipeline,
- PipelineStageDefinition<TIntermediate, TOutput> stage,
- IBsonSerializer<TOutput> outputSerializer = null)
- {
- _pipeline = Ensure.IsNotNull(pipeline, nameof(pipeline));
- _stage = Ensure.IsNotNull(stage, nameof(stage));
- _outputSerializer = outputSerializer; // can be null
- }
- /// <inheritdoc/>
- public override IBsonSerializer<TOutput> OutputSerializer => _outputSerializer;
- /// <inheritdoc/>
- public override IEnumerable<IPipelineStageDefinition> Stages => _pipeline.Stages.Concat(new[] { _stage });
- /// <inheritdoc/>
- public override RenderedPipelineDefinition<TOutput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry)
- {
- var renderedPipeline = _pipeline.Render(inputSerializer, serializerRegistry);
- var renderedStage = _stage.Render(renderedPipeline.OutputSerializer, serializerRegistry);
- var documents = renderedPipeline.Documents.Concat(new[] { renderedStage.Document });
- var outputSerializer = _outputSerializer ?? renderedStage.OutputSerializer;
- return new RenderedPipelineDefinition<TOutput>(documents, outputSerializer);
- }
- }
- /// <summary>
- /// Represents an empty pipeline.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- public sealed class EmptyPipelineDefinition<TInput> : PipelineDefinition<TInput, TInput>
- {
- private readonly IBsonSerializer<TInput> _inputSerializer;
- /// <summary>
- /// Initializes a new instance of the <see cref="EmptyPipelineDefinition{TOutput}"/> class.
- /// </summary>
- /// <param name="inputSerializer">The output serializer.</param>
- public EmptyPipelineDefinition(IBsonSerializer<TInput> inputSerializer = null)
- {
- _inputSerializer = inputSerializer; // can be null
- }
- /// <inheritdoc/>
- public override IBsonSerializer<TInput> OutputSerializer => _inputSerializer;
- /// <inheritdoc/>
- public override IEnumerable<IPipelineStageDefinition> Stages => Enumerable.Empty<IPipelineStageDefinition>();
- /// <inheritdoc/>
- public override RenderedPipelineDefinition<TInput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry)
- {
- var documents = Enumerable.Empty<BsonDocument>();
- return new RenderedPipelineDefinition<TInput>(documents, _inputSerializer ?? inputSerializer);
- }
- }
- /// <summary>
- /// Represents a pipeline consisting of an existing pipeline with one additional stage prepended.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- public sealed class PrependedStagePipelineDefinition<TInput, TIntermediate, TOutput> : PipelineDefinition<TInput, TOutput>
- {
- private readonly IBsonSerializer<TOutput> _outputSerializer;
- private readonly PipelineDefinition<TIntermediate, TOutput> _pipeline;
- private readonly PipelineStageDefinition<TInput, TIntermediate> _stage;
- /// <summary>
- /// Initializes a new instance of the <see cref="PrependedStagePipelineDefinition{TInput, TIntermediate, TOutput}" /> class.
- /// </summary>
- /// <param name="stage">The stage.</param>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="outputSerializer">The output serializer.</param>
- public PrependedStagePipelineDefinition(
- PipelineStageDefinition<TInput, TIntermediate> stage,
- PipelineDefinition<TIntermediate, TOutput> pipeline,
- IBsonSerializer<TOutput> outputSerializer = null)
- {
- _stage = Ensure.IsNotNull(stage, nameof(stage));
- _pipeline = Ensure.IsNotNull(pipeline, nameof(pipeline));
- _outputSerializer = outputSerializer; // can be null
- }
- /// <inheritdoc/>
- public override IBsonSerializer<TOutput> OutputSerializer => _outputSerializer;
- /// <inheritdoc/>
- public override IEnumerable<IPipelineStageDefinition> Stages => new[] { _stage }.Concat(_pipeline.Stages);
- /// <inheritdoc/>
- public override RenderedPipelineDefinition<TOutput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry)
- {
- var renderedStage = _stage.Render(inputSerializer, serializerRegistry);
- var renderedPipeline = _pipeline.Render(renderedStage.OutputSerializer, serializerRegistry);
- var documents = new[] { renderedStage.Document }.Concat(renderedPipeline.Documents);
- var outputSerializer = _outputSerializer ?? renderedPipeline.OutputSerializer;
- return new RenderedPipelineDefinition<TOutput>(documents, outputSerializer);
- }
- }
- /// <summary>
- /// Represents a pipeline with the output serializer replaced.
- /// </summary>
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
- /// <typeparam name="TIntermediate">The type of the intermediate documents.</typeparam>
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
- /// <seealso cref="MongoDB.Driver.PipelineDefinition{TInput, TOutput}" />
- public sealed class ReplaceOutputSerializerPipelineDefinition<TInput, TIntermediate, TOutput> : PipelineDefinition<TInput, TOutput>
- {
- private readonly IBsonSerializer<TOutput> _outputSerializer;
- private readonly PipelineDefinition<TInput, TIntermediate> _pipeline;
- /// <summary>
- /// Initializes a new instance of the <see cref="ReplaceOutputSerializerPipelineDefinition{TInput, TIntermediate, TOutput}"/> class.
- /// </summary>
- /// <param name="pipeline">The pipeline.</param>
- /// <param name="outputSerializer">The output serializer.</param>
- public ReplaceOutputSerializerPipelineDefinition(
- PipelineDefinition<TInput, TIntermediate> pipeline,
- IBsonSerializer<TOutput> outputSerializer = null)
- {
- _pipeline = Ensure.IsNotNull(pipeline, nameof(pipeline));
- _outputSerializer = outputSerializer; // can be null
- }
- /// <inheritdoc/>
- public override IBsonSerializer<TOutput> OutputSerializer => _outputSerializer;
- /// <inheritdoc/>
- public override IEnumerable<IPipelineStageDefinition> Stages => _pipeline.Stages;
- /// <inheritdoc/>
- public override RenderedPipelineDefinition<TOutput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry)
- {
- var renderedPipeline = _pipeline.Render(inputSerializer, serializerRegistry);
- var outputSerializer = _outputSerializer ?? serializerRegistry.GetSerializer<TOutput>();
- return new RenderedPipelineDefinition<TOutput>(renderedPipeline.Documents, outputSerializer);
- }
- }
- }
|