Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9357

make emit arguments mutable in MapReduce or fail if they're changed

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Gone away
    • 2.4.1
    • None
    • MapReduce
    • None
    • Minor Change

    Description

      Just was the case for reduce arguments in SERVER-8624, this in the emit function is immutable. This can produce unexpected results.

      Small example code:

      db.t.insert({test: 1})
      function map() {
         this.test += 1;
         emit(this._id, this.test);
      }
       
      function reduce(key, values) {
         var r = {test: 0};
         values.forEach(function (t) {
            r.test += t.test;
         });
         return r;
      }
       
      var result = db.t.mapReduce(map, reduce,{ out: { inline: 1 }});
      printjson(result);

      The following code returns

      {test:1}

      and "cannot write property test to read-only object" is written in mongodb.log. I expected

      {test:2}

      in the value OR the write to this in the map to this to fail with an exception (just like the standard Object.freeze() would do). Just keeping the old value is confusing. The logged messages are hard to link to specific queries, since no context is provided in these messages, making issues related to this hard to debug.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            markvandertol Mark van der Tol
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: