Ejemplo n.º 1
0
 public override Task <IAsyncCursor <TResult> > MapReduceAsync <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     options        = options ?? new MapReduceOptions <TDocument, TResult>();
     options.Filter = CombineFilters(options.Filter);
     return(_wrappedCollection.MapReduceAsync(map, reduce, options, cancellationToken));
 }
 public abstract Task <IAsyncCursor <TResult> > MapReduceAsync <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken));
 public virtual Task <IAsyncCursor <TResult> > MapReduceAsync <TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
 private FindOperation <TResult> CreateMapReduceOutputToCollectionFindOperation <TResult>(MapReduceOptions <TDocument, TResult> options, CollectionNamespace outputCollectionNamespace, IBsonSerializer <TResult> resultSerializer)
 {
     return(new FindOperation <TResult>(
                outputCollectionNamespace,
                resultSerializer,
                _messageEncoderSettings)
     {
         MaxTime = options.MaxTime,
         ReadConcern = _settings.ReadConcern
     });
 }
 public virtual IAsyncCursor <TResult> MapReduce <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
        private MapReduceOutputToCollectionOperation CreateMapReduceOutputToCollectionOperation <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options, MapReduceOutputOptions outputOptions)
        {
            var collectionOutputOptions = (MapReduceOutputOptions.CollectionOutput)outputOptions;
            var databaseNamespace       = collectionOutputOptions.DatabaseName == null ?
                                          _collectionNamespace.DatabaseNamespace :
                                          new DatabaseNamespace(collectionOutputOptions.DatabaseName);
            var outputCollectionNamespace = new CollectionNamespace(databaseNamespace, collectionOutputOptions.CollectionName);

            return(new MapReduceOutputToCollectionOperation(
                       _collectionNamespace,
                       outputCollectionNamespace,
                       map,
                       reduce,
                       _messageEncoderSettings)
            {
                BypassDocumentValidation = options.BypassDocumentValidation,
                Filter = options.Filter == null ? null : options.Filter.Render(_documentSerializer, _settings.SerializerRegistry),
                FinalizeFunction = options.Finalize,
                JavaScriptMode = options.JavaScriptMode,
                Limit = options.Limit,
                MaxTime = options.MaxTime,
                NonAtomicOutput = collectionOutputOptions.NonAtomic,
                Scope = options.Scope,
                OutputMode = collectionOutputOptions.OutputMode,
                ShardedOutput = collectionOutputOptions.Sharded,
                Sort = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry),
                Verbose = options.Verbose
            });
        }
Ejemplo n.º 7
0
 private MapReduceOperation <TResult> CreateMapReduceOperation <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options, IBsonSerializer <TResult> resultSerializer)
 {
     return(new MapReduceOperation <TResult>(
                _collectionNamespace,
                map,
                reduce,
                resultSerializer,
                _messageEncoderSettings)
     {
         Filter = options.Filter == null ? null : options.Filter.Render(_documentSerializer, _settings.SerializerRegistry),
         FinalizeFunction = options.Finalize,
         JavaScriptMode = options.JavaScriptMode,
         Limit = options.Limit,
         MaxTime = options.MaxTime,
         ReadConcern = _settings.ReadConcern,
         Scope = options.Scope,
         Sort = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry),
         Verbose = options.Verbose
     });
 }
Ejemplo n.º 8
0
        public override async Task <IAsyncCursor <TResult> > MapReduceAsync <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(map, nameof(map));
            Ensure.IsNotNull(reduce, nameof(reduce));
            options = options ?? new MapReduceOptions <TDocument, TResult>();

            var outputOptions    = options.OutputOptions ?? MapReduceOutputOptions.Inline;
            var resultSerializer = ResolveResultSerializer <TResult>(options.ResultSerializer);

            if (outputOptions == MapReduceOutputOptions.Inline)
            {
                var operation = CreateMapReduceOperation(map, reduce, options, resultSerializer);
                return(await ExecuteReadOperationAsync(operation, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                var mapReduceOperation = CreateMapReduceOutputToCollectionOperation(map, reduce, options, outputOptions);
                await ExecuteWriteOperationAsync(mapReduceOperation, cancellationToken).ConfigureAwait(false);

                var findOperation = CreateMapReduceOutputToCollectionFindOperation <TResult>(options, mapReduceOperation.OutputCollectionNamespace, resultSerializer);

                // we want to delay execution of the find because the user may
                // not want to iterate the results at all...
                var deferredCursor = new DeferredAsyncCursor <TResult>(
                    ct => ExecuteReadOperation(findOperation, ReadPreference.Primary, ct),
                    ct => ExecuteReadOperationAsync(findOperation, ReadPreference.Primary, ct));
                return(await Task.FromResult(deferredCursor).ConfigureAwait(false));
            }
        }
 public override IAsyncCursor <TResult> MapReduce <TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     options        = options ?? new MapReduceOptions <TDocument, TResult>();
     options.Filter = CombineFilters(options.Filter);
     return(_wrappedCollection.MapReduce(session, map, reduce, options, cancellationToken));
 }
Ejemplo n.º 10
0
        public override async Task <IAsyncCursor <TResult> > MapReduceAsync <TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(map, nameof(map));
            Ensure.IsNotNull(reduce, nameof(reduce));

            options = options ?? new MapReduceOptions <TDocument, TResult>();
            var outputOptions    = options.OutputOptions ?? MapReduceOutputOptions.Inline;
            var resultSerializer = ResolveResultSerializer <TResult>(options.ResultSerializer);

            if (outputOptions == MapReduceOutputOptions.Inline)
            {
                var operation = new MapReduceOperation <TResult>(
                    _collectionNamespace,
                    map,
                    reduce,
                    resultSerializer,
                    _messageEncoderSettings)
                {
                    Filter           = options.Filter == null ? null : options.Filter.Render(_documentSerializer, _settings.SerializerRegistry),
                    FinalizeFunction = options.Finalize,
                    JavaScriptMode   = options.JavaScriptMode,
                    Limit            = options.Limit,
                    MaxTime          = options.MaxTime,
                    Scope            = options.Scope,
                    Sort             = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry),
                    Verbose          = options.Verbose
                };

                return(await ExecuteReadOperationAsync(operation, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                var collectionOutputOptions = (MapReduceOutputOptions.CollectionOutput)outputOptions;
                var databaseNamespace       = collectionOutputOptions.DatabaseName == null ?
                                              _collectionNamespace.DatabaseNamespace :
                                              new DatabaseNamespace(collectionOutputOptions.DatabaseName);
                var outputCollectionNamespace = new CollectionNamespace(databaseNamespace, collectionOutputOptions.CollectionName);

                var operation = new MapReduceOutputToCollectionOperation(
                    _collectionNamespace,
                    outputCollectionNamespace,
                    map,
                    reduce,
                    _messageEncoderSettings)
                {
                    BypassDocumentValidation = options.BypassDocumentValidation,
                    Filter           = options.Filter == null ? null : options.Filter.Render(_documentSerializer, _settings.SerializerRegistry),
                    FinalizeFunction = options.Finalize,
                    JavaScriptMode   = options.JavaScriptMode,
                    Limit            = options.Limit,
                    MaxTime          = options.MaxTime,
                    NonAtomicOutput  = collectionOutputOptions.NonAtomic,
                    Scope            = options.Scope,
                    OutputMode       = collectionOutputOptions.OutputMode,
                    ShardedOutput    = collectionOutputOptions.Sharded,
                    Sort             = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry),
                    Verbose          = options.Verbose
                };

                await ExecuteWriteOperationAsync(operation, cancellationToken).ConfigureAwait(false);

                var findOperation = new FindOperation <TResult>(
                    outputCollectionNamespace,
                    resultSerializer,
                    _messageEncoderSettings)
                {
                    MaxTime = options.MaxTime
                };

                // we want to delay execution of the find because the user may
                // not want to iterate the results at all...
                var deferredCursor = new DeferredAsyncCursor <TResult>(
                    ct => ExecuteReadOperation(findOperation, ReadPreference.Primary, ct),
                    ct => ExecuteReadOperationAsync(findOperation, ReadPreference.Primary, ct));
                return(await Task.FromResult(deferredCursor).ConfigureAwait(false));
            }
        }