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, _linqProvider); 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)); } }
public static ICoreSessionHandle ToCoreSession(this IClientSessionHandle clientSession) { var coreSession = new ClientSessionWrappingCoreSession(clientSession.Fork()); return(new CoreSessionHandle(coreSession)); }
public IClientSessionHandle Fork() { return(_sessionHandle.Fork()); }