| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268 |
- /* Copyright 2016-present 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 $changeStream stage to the pipeline.
- /// Normally you would prefer to use the Watch method of <see cref="IMongoCollection{TDocument}" />.
- /// Only use this method if subsequent stages project away the resume token (the _id)
- /// or you don't want the resulting cursor to automatically resume.
- /// </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="options">The options.</param>
- /// <returns>
- /// The fluent aggregate interface.
- /// </returns>
- public static PipelineDefinition<TInput, ChangeStreamDocument<TIntermediate>> ChangeStream<TInput, TIntermediate>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- ChangeStreamStageOptions options = null)
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.ChangeStream<TIntermediate>(options));
- }
- /// <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 $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="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="foreignCollection">The foreign collection.</param>
- /// <param name="let">The "let" definition.</param>
- /// <param name="lookupPipeline">The lookup pipeline.</param>
- /// <param name="as">The as field in <typeparamref name="TOutput" /> in which to place the results of the lookup pipeline.</param>
- /// <param name="options">The options.</param>
- /// <returns>The stage.</returns>
- public static PipelineDefinition<TInput, TOutput> Lookup<TInput, TIntermediate, TForeignDocument, TAsElement, TAs, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TForeignDocument> foreignCollection,
- BsonDocument let,
- PipelineDefinition<TForeignDocument, TAsElement> lookupPipeline,
- FieldDefinition<TOutput, TAs> @as,
- AggregateLookupOptions<TForeignDocument, TOutput> options = null)
- where TAs : IEnumerable<TAsElement>
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Lookup<TIntermediate, TForeignDocument, TAsElement, TAs, TOutput>(
- foreignCollection,
- let,
- lookupPipeline,
- @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="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="foreignCollection">The foreign collection.</param>
- /// <param name="let">The "let" definition.</param>
- /// <param name="lookupPipeline">The lookup pipeline.</param>
- /// <param name="as">The as field in <typeparamref name="TOutput" /> in which to place the results of the lookup pipeline.</param>
- /// <param name="options">The options.</param>
- /// <returns>The stage.</returns>
- public static PipelineDefinition<TInput, TOutput> Lookup<TInput, TIntermediate, TForeignDocument, TAsElement, TAs, TOutput>(
- this PipelineDefinition<TInput, TIntermediate> pipeline,
- IMongoCollection<TForeignDocument> foreignCollection,
- BsonDocument let,
- PipelineDefinition<TForeignDocument, TAsElement> lookupPipeline,
- Expression<Func<TOutput, TAs>> @as,
- AggregateLookupOptions<TForeignDocument, TOutput> options = null)
- where TAs : IEnumerable<TAsElement>
- {
- Ensure.IsNotNull(pipeline, nameof(pipeline));
- return pipeline.AppendStage(PipelineStageDefinitionBuilder.Lookup<TIntermediate, TForeignDocument, TAsElement, TAs, TOutput>(
- foreignCollection,
- let,
- lookupPipeline,
- @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);
- }
- }
- }
|