MongoDB.Driver.Builders.MapReduceOptionsBuilder.SetScope C# (CSharp) Method

SetScope() public method

Sets a scope that contains variables that can be accessed by the map, reduce and finalize functions.
public SetScope ( IMongoScope scope ) : MapReduceOptionsBuilder
scope IMongoScope The scope.
return MapReduceOptionsBuilder
        public MapReduceOptionsBuilder SetScope(IMongoScope scope)
        {
            _document["scope"] = BsonDocumentWrapper.Create(scope);
            return this;
        }

Usage Example

Ejemplo n.º 1
0
        protected override void BeginProcessing()
        {
            var mc = TargetCollection.Collection as MongoCollection;
            if (mc == null) ThrowNotImplementedForFiles("MapReduce");

            var options = new MapReduceOptionsBuilder();

            options.SetJSMode(JSMode);

            if (Function.Length == 3)
                options.SetFinalize(new BsonJavaScript(Function[2]));

            if (_Query != null)
                options.SetQuery(_Query);

            if (_SortBy != null)
                options.SetSortOrder(_SortBy);

            if (First > 0)
                options.SetLimit(First);

            if (Scope != null)
                options.SetScope(new ScopeDocument(Scope));

            if (!string.IsNullOrEmpty(OutCollection) && OutMode == MapReduceOutputMode.Inline)
                OutMode = MapReduceOutputMode.Replace;

            var output = new MapReduceOutput();
            output.Mode = OutMode;
            output.DatabaseName = OutDatabase;
            output.CollectionName = OutCollection;
            options.SetOutput(output);

            var result = mc.MapReduce(new BsonJavaScript(Function[0]), new BsonJavaScript(Function[1]), options);

            if (ResultVariable != null)
                SessionState.PSVariable.Set(ResultVariable, result);

            if (OutMode != MapReduceOutputMode.Inline)
                return;

            var documentAs = _ParameterAs ?? new ParameterAs(null);

            //_131018_160000
            foreach (var it in result.GetInlineResultsAs(documentAs.Type))
                WriteObject(it);
        }