[SERVER-6994] NumberLong(0).toNumber silently fails Created: 10/Sep/12  Updated: 15/Feb/13  Resolved: 11/Sep/12

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.0.4, 2.2.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Steven Hadfield Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Centos 6.3 x64 running MongoDB 2.2.0,
Centos 5.8 x64 running MongoDB 2.0.4


Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by Tad Marshall [ 11/Sep/12 ]

No problem, I'll resolve this ticket for now. Please reopen if you find that it is our problem.

Comment by Steven Hadfield [ 11/Sep/12 ]

I investigated more and I think this is actually a Fedora-specific issue. I was connecting to a number of Centos servers, but using a Fedora-packaged client (2.0.6-2 and 2.0.7). When I installed the 10gen package, it worked fine. I'll create a bug-report over there instead. Sorry for reporting to the wrong place.

Comment by Tad Marshall [ 11/Sep/12 ]

Are you saying that you do not get the "Expected (when run from the shell):" output when run from the shell, or you do get this output?

In my quick test, I do get this output in the shell in 2.2.0. So is this a map-reduce issue only?

When you say "NumberLong(0) would kill a function" are you saying that it throws a JavaScript exception or crashes somehow or somehow aborts a map or reduce function?

Do you think that this issue is Centos-specific, or should I see it on all platforms? I tested on Ubuntu 12.04 and on Windows and it worked (in the shell) on both.

Comment by Steven Hadfield [ 10/Sep/12 ]

I forgot to add that my work-around is to use the toString() function to check if the value is 0.

 
if (value.toString() == 'NumberLong(0)') {
    print('value is 0');
}

Generated at Thu Feb 08 03:13:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.