コード例 #1
0
        public override string ToString()
        {
            var sb = new StringBuilder("aggregate([");

            if (_stages.Count > 0)
            {
                var pipeline         = new PipelineStagePipelineDefinition <TDocument, TResult>(_stages);
                var renderedPipeline = pipeline.Render(_collection.DocumentSerializer, _collection.Settings.SerializerRegistry);
                sb.Append(string.Join(", ", renderedPipeline.Documents.Select(x => x.ToString())));
            }
            sb.Append("])");
            return(sb.ToString());
        }
コード例 #2
0
        public override IOrderedAggregateFluent <TResult> ThenBy(SortDefinition <TResult> newSort)
        {
            Ensure.IsNotNull(newSort, nameof(newSort));
            var stages       = _pipeline.Stages.ToList();
            var oldSortStage = (SortPipelineStageDefinition <TResult>)stages[stages.Count - 1];
            var oldSort      = oldSortStage.Sort;
            var combinedSort = Builders <TResult> .Sort.Combine(oldSort, newSort);

            var combinedSortStage = PipelineStageDefinitionBuilder.Sort(combinedSort);

            stages[stages.Count - 1] = combinedSortStage;
            var newPipeline = new PipelineStagePipelineDefinition <TDocument, TResult>(stages);

            return((IOrderedAggregateFluent <TResult>)WithPipeline(newPipeline));
        }
コード例 #3
0
        private PipelineDefinition <TDocument, TResult> CreateFilteredPipeline <TResult>(PipelineDefinition <TDocument, TResult> pipeline)
        {
            const string matchOperatorName = "$match";

            var filterStage = new DelegatedPipelineStageDefinition <TDocument, TDocument>(
                matchOperatorName,
                (s, sr) =>
            {
                var renderedFilter = _filter.Render(s, sr);
                return(new RenderedPipelineStageDefinition <TDocument>(matchOperatorName, new BsonDocument(matchOperatorName, renderedFilter), s));
            });

            var filterPipeline   = new PipelineStagePipelineDefinition <TDocument, TDocument>(new[] { filterStage });
            var combinedPipeline = new CombinedPipelineDefinition <TDocument, TDocument, TResult>(
                filterPipeline,
                pipeline);

            return(new OptimizingPipelineDefinition <TDocument, TResult>(combinedPipeline));
        }
コード例 #4
0
        // public methods
        public override Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            const string matchOperatorName = "$match";

            var filterStage = new DelegatedPipelineStageDefinition <TDocument, TDocument>(
                matchOperatorName,
                (s, sr) =>
            {
                var renderedFilter = _filter.Render(s, sr);
                return(new RenderedPipelineStageDefinition <TDocument>(matchOperatorName, new BsonDocument(matchOperatorName, renderedFilter), s));
            });

            var filterPipeline   = new PipelineStagePipelineDefinition <TDocument, TDocument>(new[] { filterStage });
            var combinedPipeline = new CombinedPipelineDefinition <TDocument, TDocument, TResult>(
                filterPipeline,
                pipeline);

            var optimizedPipeline = new OptimizingPipelineDefinition <TDocument, TResult>(combinedPipeline);

            return(_wrappedCollection.AggregateAsync(optimizedPipeline, options, cancellationToken));
        }
コード例 #5
0
        public override Task <IAsyncCursor <TResult> > ToCursorAsync(CancellationToken cancellationToken)
        {
            var pipeline = new PipelineStagePipelineDefinition <TDocument, TResult>(_stages);

            return(_collection.AggregateAsync(pipeline, _options, cancellationToken));
        }