[SERVER-2688] temporary collection created by mapReduce returned Double instead of Int Created: 06/Mar/11 Updated: 29/Aug/11 Resolved: 06/Mar/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 1.6.5 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Minor - P4 |
| Reporter: | Honnix Liang | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Mac OS X 64bit, mongoDB-1.6.5 64bit, mongodb-java-driver-2.4 |
||
| Participants: |
| Description |
|
Not sure whether it is a bug, so just fire a question. I have following map/reduce functions defined: m = function() { emit("totalClickCount", this.clickCount); }r = function(key, values) { return Array.sum(values); }If I run everything in mongodb console, I can get result as I expected: { "_id" : "totalClickCount", "value" : 2 }, here value is an integer; but if I use mongodb-java-driver to do exactly the same thing, it returns double instead of integer for "value". Also, I tried to query the temporary collection directly in mongodb console, and it is integer as well. I tried to debug, and saw that for returned BSON stream, data type was "NUMBER" which means a floating point according to BSON's spec, so seems that mongodb-java-driver is correct. But why does server return a double type? |
| Comments |
| Comment by Honnix Liang [ 07/Mar/11 ] |
|
Well, then I got it. I'm totally a newbie on javascript... |
| Comment by Eliot Horowitz (Inactive) [ 07/Mar/11 ] |
|
Yes, javascript will display doubles that fall on whole numbers as integers |
| Comment by Honnix Liang [ 07/Mar/11 ] |
|
but for me, it is just the opposite, in shell, I got something like integer, while via API, it is double. so do you mean that even in shell, I also got an double, while it displayed like an integer instead? |
| Comment by Scott Hernandez (Inactive) [ 06/Mar/11 ] |
|
In javascript the default number type is a double. If you want to return an integer then you must create a special object to represent it; at the moment there is only support for a 64bit integer (long) in javascript with the NumberLong class. http://www.mongodb.org/display/DOCS/mongo+-+The+Interactive+Shell#mongo-TheInteractiveShell-Numbers You can vote on this for better 32bit int support in javascript: http://jira.mongodb.org/browse/SERVER-854 |