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

NumberLong(0).toNumber silently fails

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.0.4, 2.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Centos 6.3 x64 running MongoDB 2.2.0,
      Centos 5.8 x64 running MongoDB 2.0.4
    • ALL

      Found an issue with NumberLong when trying to work with the value 0. Inside a Map-Reduce function, I was trying to get a sum of values that included zero. Some of the resulting documents ended up with a value of null. After a long time of hunting, limited it down the fact that NumberLong(0) would kill a function if trying to convert to an integer (NumberLong.toNumber()) with no stack traces or log entries.

      I would also note that I could find close to no documentation for NumberLong in the wiki.

      Here's a test case that isolates the issue for me:

      var test = function() { 
          print('NumberLong(0) test');
          var test1 = NumberLong(0);
          print(test1.toNumber());
          print('Unreached 1');
          // Also fails 
          print(test1 + 1);
          print('Unreached 2');
          return {'some' : 'result'};
      };
      test();
      

      Expected (when run from the shell):

      NumberLong(0) test
      0
      Unreached 1
      1
      Unreached 2
      { "some" : "result" }
      

      Result:

      NumberLong(0) test
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            steven.hadfield Steven Hadfield
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: