Beispiel #1
0
        /// <summary>
        /// Appends a $facet stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="facets">The facets.</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <AggregateFacetResults> Facet <TResult>(
            this IAggregateFluent <TResult> aggregate,
            IEnumerable <AggregateFacet <TResult> > facets)
        {
            var newResultSerializer = new AggregateFacetResultsSerializer(
                facets.Select(f => f.Name),
                facets.Select(f => f.OutputSerializer ?? BsonSerializer.SerializerRegistry.GetSerializer(f.OutputType)));
            var options = new AggregateFacetOptions <AggregateFacetResults> {
                NewResultSerializer = newResultSerializer
            };

            return(aggregate.Facet(facets, options));
        }
Beispiel #2
0
        public override IAggregateFluent <TNewResult> Facet <TNewResult>(
            IEnumerable <AggregateFacet <TResult> > facets,
            AggregateFacetOptions <TNewResult> options = null)
        {
            const string operatorName       = "$facet";
            var          materializedFacets = facets.ToArray();
            var          stage = new DelegatedPipelineStageDefinition <TResult, TNewResult>(
                operatorName,
                (s, sr) =>
            {
                var facetsDocument = new BsonDocument();
                foreach (var facet in materializedFacets)
                {
                    var renderedPipeline = facet.RenderPipeline(s, sr);
                    facetsDocument.Add(facet.Name, renderedPipeline);
                }
                var document         = new BsonDocument("$facet", facetsDocument);
                var resultSerializer = options?.NewResultSerializer ?? sr.GetSerializer <TNewResult>();
                return(new RenderedPipelineStageDefinition <TNewResult>(operatorName, document, resultSerializer));
            });

            return(AppendStage <TNewResult>(stage));
        }
 public override IAggregateFluent <TNewResult> Facet <TNewResult>(
     IEnumerable <AggregateFacet <TResult> > facets,
     AggregateFacetOptions <TNewResult> options = null)
 {
     return(WithPipeline(_pipeline.Facet(facets, options)));
 }
Beispiel #4
0
 /// <inheritdoc />
 public virtual IAggregateFluent <TNewResult> Facet <TNewResult>(
     IEnumerable <AggregateFacet <TResult> > facets,
     AggregateFacetOptions <TNewResult> options = null)
 {
     throw new NotImplementedException();
 }