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

SetSortOrder() public method

Sets the sort order (useful in combination with SetLimit, your map function should not depend on the order the documents are sent to it).
public SetSortOrder ( ) : MapReduceOptionsBuilder
return MapReduceOptionsBuilder
        public MapReduceOptionsBuilder SetSortOrder(params string[] keys)
        {
            return SetSortOrder(SortBy.Ascending(keys));
        }

Same methods

MapReduceOptionsBuilder::SetSortOrder ( IMongoSortBy sortBy ) : MapReduceOptionsBuilder

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