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); }