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

Under v8, objects in map() have null value for .constructor

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • 1.4.2
    • None
    • None
    • OS X, with v8 build

    Description

      From my forum post at:
      http://groups.google.com/group/mongodb-user/browse_thread/thread/2e99cf6df485f0f5#

      Under V8, the 'this' object in the map function of a mapreduce call has a null value for .constructor. I'm not sure if this if malformed JS, or by design, but if it is by design, then it would be nice if tojson() could handle such objects (issue 1118)

      Reproducing the test case from the forum post:

      > rec =

      {foo: 'bar'} { "foo" : "bar" }

      > db.test_coll.save(rec)
      > reduceTest = function(key, valueArray)

      { ... print("in reduceTest"); ... return 2; ... }

      ;
      > mapTest = function()

      { ... print("in mapTest"); ... emit('blah', 1); ... }

      > var res = db.runCommand(

      {mapreduce: 'test_coll', map: mapTest, reduce: reduceTest, out: 'test_mr_out1', verbose: true}

      );
      > res

      { "result" : "test_mr_out1", //... etc ... }

      ,
      "ok" : 1
      }

      // works fine without tojson() call

      > mapTestFail = function()

      { ... print("in mapTest"); ... print(tojson(this)); ... emit('blah', 1); ... }

      ;
      > var res = db.runCommand(

      {mapreduce: 'test_coll', map: mapTestFail, reduce: reduceTest, out: 'test_mr_out1', verbose: true}

      );
      > res

      {
      "errmsg" : "assertion: map invoke failed: error in invoke:
      localConnect 1:397 TypeError: Cannot read property 'tojson' of null
      if ( typeof( x.constructor.tojson ) == \"function\" &&
      x.constructor.tojson != t
      ^
      ",
      "ok" : 0
      }

      It's likely that something out of this and 1118 is invalid, but I feel that at least one of them is probably a valid issue.

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            admackin Andy MacKinlay
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: