Exemplo n.º 1
0
 /// <inheritdoc />
 public virtual IAggregateFluent <TResult> UnionWith <TWith>(
     IMongoCollection <TWith> withCollection,
     PipelineDefinition <TWith, TResult> withPipeline = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 2
0
        public override async Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options, CancellationToken cancellationToken)
        {
            var renderedPipeline = Ensure.IsNotNull(pipeline, nameof(pipeline)).Render(_documentSerializer, _settings.SerializerRegistry);

            options = options ?? new AggregateOptions();

            var last = renderedPipeline.Documents.LastOrDefault();

            if (last != null && last.GetElement(0).Name == "$out")
            {
                var aggregateOperation = CreateAggregateToCollectionOperation(renderedPipeline, options);
                await ExecuteWriteOperationAsync(aggregateOperation, cancellationToken).ConfigureAwait(false);

                // we want to delay execution of the find because the user may
                // not want to iterate the results at all...
                var findOperation  = CreateAggregateToCollectionFindOperation(last, renderedPipeline.OutputSerializer, options);
                var deferredCursor = new DeferredAsyncCursor <TResult>(
                    ct => ExecuteReadOperation(findOperation, ReadPreference.Primary, ct),
                    ct => ExecuteReadOperationAsync(findOperation, ReadPreference.Primary, ct));
                return(await Task.FromResult <IAsyncCursor <TResult> >(deferredCursor).ConfigureAwait(false));
            }
            else
            {
                var aggregateOperation = CreateAggregateOperation(renderedPipeline, options);
                return(await ExecuteReadOperationAsync(aggregateOperation, cancellationToken).ConfigureAwait(false));
            }
        }
Exemplo n.º 3
0
 // protected methods
 protected override IAggregateFluent <TNewResult> WithPipeline <TNewResult>(PipelineDefinition <TDocument, TNewResult> pipeline)
 {
     return(new CollectionAggregateFluent <TDocument, TNewResult>(_session, _collection, pipeline, _options));
 }
        public override IAsyncCursor <TResult> Aggregate <TResult>(IClientSessionHandle session, PipelineDefinition <NoPipelineInput, TResult> pipeline, AggregateOptions options, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(session, nameof(session));
            var renderedPipeline = Ensure.IsNotNull(pipeline, nameof(pipeline)).Render(NoPipelineInputSerializer.Instance, _settings.SerializerRegistry);

            options = options ?? new AggregateOptions();

            var lastStage     = renderedPipeline.Documents.LastOrDefault();
            var lastStageName = lastStage?.GetElement(0).Name;

            if (lastStage != null && (lastStageName == "$out" || lastStageName == "$merge"))
            {
                var aggregateOperation = CreateAggregateToCollectionOperation(renderedPipeline, options);
                ExecuteWriteOperation(session, aggregateOperation, cancellationToken);

                // we want to delay execution of the find because the user may
                // not want to iterate the results at all...
                var findOperation  = CreateAggregateToCollectionFindOperation(lastStage, renderedPipeline.OutputSerializer, options);
                var forkedSession  = session.Fork();
                var deferredCursor = new DeferredAsyncCursor <TResult>(
                    () => forkedSession.Dispose(),
                    ct => ExecuteReadOperation(forkedSession, findOperation, ReadPreference.Primary, ct),
                    ct => ExecuteReadOperationAsync(forkedSession, findOperation, ReadPreference.Primary, ct));
                return(deferredCursor);
            }
            else
            {
                var aggregateOperation = CreateAggregateOperation(renderedPipeline, options);
                return(ExecuteReadOperation(session, aggregateOperation, cancellationToken));
            }
        }
        private CreateViewOperation CreateCreateViewOperation <TDocument, TResult>(string viewName, string viewOn, PipelineDefinition <TDocument, TResult> pipeline, CreateViewOptions <TDocument> options)
        {
            var serializerRegistry = options.SerializerRegistry ?? BsonSerializer.SerializerRegistry;
            var documentSerializer = options.DocumentSerializer ?? serializerRegistry.GetSerializer <TDocument>();
            var pipelineDocuments  = pipeline.Render(documentSerializer, serializerRegistry).Documents;

            return(new CreateViewOperation(_databaseNamespace, viewName, viewOn, pipelineDocuments, GetMessageEncoderSettings())
            {
                Collation = options.Collation,
                WriteConcern = _settings.WriteConcern
            });
        }
Exemplo n.º 6
0
 protected abstract IAggregateFluent <TNewResult> WithPipeline <TNewResult>(PipelineDefinition <TInput, TNewResult> pipeline);
Exemplo n.º 7
0
 /// <inheritdoc />
 public virtual Task CreateViewAsync <TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition <TDocument, TResult> pipeline, CreateViewOptions <TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
 public override Task CreateViewAsync <TDocument, TResult>(string viewName, string viewOn, PipelineDefinition <TDocument, TResult> pipeline, CreateViewOptions <TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UsingImplicitSessionAsync(session => CreateViewAsync(session, viewName, viewOn, pipeline, options, cancellationToken), cancellationToken));
 }
        public override Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(IClientSessionHandle session, PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var filteredPipeline = CreateFilteredPipeline(pipeline);

            return(_wrappedCollection.AggregateAsync(session, filteredPipeline, options, cancellationToken));
        }
Exemplo n.º 10
0
 /// <inheritdoc />
 public virtual void CreateView <TDocument, TResult>(string viewName, string viewOn, PipelineDefinition <TDocument, TResult> pipeline, CreateViewOptions <TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
        // public methods
        public override IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var filteredPipeline = CreateFilteredPipeline(pipeline);

            return(_wrappedCollection.Aggregate(filteredPipeline, options, cancellationToken));
        }
        private PipelineDefinition <TDocument, TResult> CreateFilteredPipeline <TResult>(PipelineDefinition <TDocument, TResult> pipeline)
        {
            var filterStage      = PipelineStageDefinitionBuilder.Match(_filter);
            var filteredPipeline = new PrependedStagePipelineDefinition <TDocument, TDocument, TResult>(filterStage, pipeline);

            return(new OptimizingPipelineDefinition <TDocument, TResult>(filteredPipeline));
        }
        public override void AggregateToCollection <TResult>(IClientSessionHandle session, PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var filteredPipeline = CreateFilteredPipeline(pipeline);

            _wrappedCollection.AggregateToCollection(session, filteredPipeline, options, cancellationToken);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a new instance of the <see cref="AggregateFacet{TInput, TOutput}" /> class.
 /// </summary>
 /// <typeparam name="TInput">The type of the input documents.</typeparam>
 /// <typeparam name="TOutput">The type of the output documents.</typeparam>
 /// <param name="name">The facet name.</param>
 /// <param name="pipeline">The facet pipeline.</param>
 /// <returns>
 /// A new instance of the <see cref="AggregateFacet{TInput, TOutput}" /> class
 /// </returns>
 public static AggregateFacet <TInput, TOutput> Create <TInput, TOutput>(string name, PipelineDefinition <TInput, TOutput> pipeline)
 {
     return(new AggregateFacet <TInput, TOutput>(name, pipeline));
 }
Exemplo n.º 15
0
 public IAggregateFluent <TNewResult> WithPipeline <TNewResult>(PipelineDefinition <TDocument, TNewResult> pipeline)
 {
     return(new AggregateFluent <TDocument, TNewResult>(_session, _collection, pipeline, _options));
 }
 public override void CreateView <TDocument, TResult>(string viewName, string viewOn, PipelineDefinition <TDocument, TResult> pipeline, CreateViewOptions <TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     UsingImplicitSession(session => CreateView(session, viewName, viewOn, pipeline, options, cancellationToken), cancellationToken);
 }
Exemplo n.º 17
0
 // constructors
 public AggregateFluent(IClientSessionHandle session, IMongoCollection <TDocument> collection, PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options)
 {
     _session    = session; // can be null
     _collection = Ensure.IsNotNull(collection, nameof(collection));
     _pipeline   = Ensure.IsNotNull(pipeline, nameof(pipeline));
     _options    = Ensure.IsNotNull(options, nameof(options));
 }
        public override Task CreateViewAsync <TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition <TDocument, TResult> pipeline, CreateViewOptions <TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(session, nameof(session));
            Ensure.IsNotNull(viewName, nameof(viewName));
            Ensure.IsNotNull(viewOn, nameof(viewOn));
            Ensure.IsNotNull(pipeline, nameof(pipeline));
            options = options ?? new CreateViewOptions <TDocument>();
            var operation = CreateCreateViewOperation(viewName, viewOn, pipeline, options);

            return(ExecuteWriteOperationAsync(session, operation, cancellationToken));
        }
Exemplo n.º 19
0
 /// <inheritdoc />
 public virtual IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
 private ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult>(
     PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline,
     ChangeStreamOptions options)
 {
     return(ChangeStreamHelper.CreateChangeStreamOperation(this, pipeline, options, _settings.ReadConcern, GetMessageEncoderSettings()));
 }
Exemplo n.º 21
0
 /// <inheritdoc />
 public abstract Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
Exemplo n.º 22
0
 // constructors
 protected AggregateFluent(IClientSessionHandle session, PipelineDefinition <TInput, TResult> pipeline, AggregateOptions options)
 {
     _session  = session; // can be null
     _pipeline = Ensure.IsNotNull(pipeline, nameof(pipeline));
     _options  = Ensure.IsNotNull(options, nameof(options));
 }
Exemplo n.º 23
0
 public OptimizingPipelineDefinition(PipelineDefinition <TInput, TOutput> wrapped)
 {
     _wrapped = wrapped;
 }
Exemplo n.º 24
0
 // protected methods
 protected override IAggregateFluent <TNewResult> WithPipeline <TNewResult>(PipelineDefinition <NoPipelineInput, TNewResult> pipeline)
 {
     return(new DatabaseAggregateFluent <TNewResult>(_session, _database, pipeline, _options));
 }
 // public methods
 public override IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <NoPipelineInput, TResult> pipeline, AggregateOptions options, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UsingImplicitSession(session => Aggregate(session, pipeline, options, cancellationToken), cancellationToken));
 }