Represents the output options of a map/reduce operation.
 /// <summary>
 /// Sets the output option (see MapReduceOutput).
 /// </summary>
 /// <param name="output">The output option.</param>
 /// <returns>The builder (so method calls can be chained).</returns>
 public MapReduceOptionsBuilder SetOutput(MapReduceOutput output)
 {
     _document["out"] = output.ToBsonValue();
     return this;
 }
 /// <summary>
 /// Sets the output option (see MapReduceOutput).
 /// </summary>
 /// <param name="output">The output option.</param>
 /// <returns>The builder (so method calls can be chained).</returns>
 public static MapReduceOptionsBuilder SetOutput(MapReduceOutput output)
 {
     return new MapReduceOptionsBuilder().SetOutput(output);
 }
 /// <summary>
 /// Sets the output option (see MapReduceOutput).
 /// </summary>
 /// <param name="output">The output option.</param>
 /// <returns>The builder (so method calls can be chained).</returns>
 public static MapReduceOptionsBuilder SetOutput(MapReduceOutput output)
 {
     return(new MapReduceOptionsBuilder().SetOutput(output));
 }
 /// <summary>
 /// Sets the output option (see MapReduceOutput).
 /// </summary>
 /// <param name="output">The output option.</param>
 /// <returns>The builder (so method calls can be chained).</returns>
 public MapReduceOptionsBuilder SetOutput(MapReduceOutput output)
 {
     _document["out"] = output.ToBsonValue();
     return(this);
 }
        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);
        }