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

SetOutput() public method

Sets the output option (see MapReduceOutput).
public SetOutput ( MapReduceOutput output ) : MapReduceOptionsBuilder
output MapReduceOutput The output option.
return MapReduceOptionsBuilder
        public MapReduceOptionsBuilder SetOutput(MapReduceOutput output)
        {
            _document["out"] = output.ToBsonValue();
            return this;
        }

Usage Example

        public async Task<int> MapReduceToDocumentid(MongoCollection collection)
        {
            string map = @"
                    function() {
                        var auditItem = this;
                        emit(auditItem.DocumentId, { count: 1 });
                    }";
            string reduce = @"        
                    function(key, values) {
                        var result = {count: 0, Key:key };

                        values.forEach(function(value){               
                            result.count += value.count;
                        });

                        return result;
                    }";

            int count = 0;
            try
            {

                var options = new MapReduceOptionsBuilder();
                //options.SetFinalize(finalize);
                options.SetOutput(MapReduceOutput.Inline);
                var results = collection.MapReduce(map, reduce, options);

                var l = new Dictionary<Guid, MapReduceResult>();

                foreach (var result in results.GetResults())
                {

                    BsonValue rVal = result["value"];
                    MapReduceResult d = BsonSerializer.Deserialize<MapReduceResult>(rVal.ToJson());
                    if (await KeyExists(d.Key))
                    {
                        log.InfoFormat("Map reduce duplicate for document id {0} ", d.Key);
                        continue;
                    }
                    count++;
                    Console.WriteLine("Adding No [{0}] Key {1} ", count, d.Key.ToString());
                    l.Add(d.Key, d);
                    var o = await AddToLocalDB(d);
                    if (count % 100 == 0)
                    {
                        log.InfoFormat("{0} document keys processed", count);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            log.InfoFormat("{0} document keys saved to local cache ");
            return count;
        }
All Usage Examples Of MongoDB.Driver.Builders.MapReduceOptionsBuilder::SetOutput