Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2049

MapReduce does not work on DB version 3.4.5

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • None
    • Affects Version/s: 2.4.4
    • Component/s: None

      MapReduce when run on db with 3.4.5. version does not produce any result. (Both with inline and output collection).

      I tried with C# driver 2.4.4:

      • on 3.4.5 version the MapReduce does not work
      • on 3.0.2 version everything works fine.

      Here's a simple snippet to use to reproduce the bug:

      // Example of input documents
      // {
      //    "_id" : ObjectId("59c52b3cb602cb6397c2ec9d"),
      //    "Timestamp" : NumberLong(1505860144116),
      //    "Value" : 14,
      //    "Date" : ISODate("2017-09-19T22:29:04.116Z")
      // }
      
      public class Program
      {
          private const string MapJs = @"function mapF() {
          const key = this.Date.getFullYear();
          const valuePerYear = { total: 1};
      
          emit(key, valuePerYear);
      }; ";
      
          private const string ReduceJS = @"function reduceF(year, values) {
          let sum = 0;
          values.forEach(v => {
              sum += v.total;
          });
          return {total: NumberInt(sum)};
      }";
      
          public static void Main()
          {
              string mongoConnectionString = "my-connection-string";
              MongoUrl mongoUrl = MongoUrl.Create(mongoConnectionString);
              MongoClient client = new MongoClient(mongoConnectionString);
              IMongoDatabase db = client.GetDatabase("ny_database_name");
              IMongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("DocInput");
              BsonJavaScript map = new BsonJavaScript(MapJs);
              BsonJavaScript reduce = new BsonJavaScript(ReduceJS);
              FilterDefinitionBuilder<BsonDocument> filterBuilder = new FilterDefinitionBuilder<BsonDocument>();
              FilterDefinition<BsonDocument> filter = filterBuilder.Empty;
              MapReduceOptions<BsonDocument, BsonDocument> options = new MapReduceOptions<BsonDocument, BsonDocument>
              {
                  Filter = filter,
                  MaxTime = TimeSpan.FromMinutes(1),
                  OutputOptions = MapReduceOutputOptions.Reduce("Result", nonAtomic: true),
                  Verbose = true
              };
              try
              {
                  collection.MapReduce(map, reduce, options).ToList();
              }
              catch (Exception ex)
              {
                  Console.WriteLine($"Exception occurred {ex.Message}");
              }
          }
      }
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            paololaurenti Paolo Laurenti
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: