[SERVER-2844] Shell inserts integers as doubles Created: 27/Mar/11 Updated: 29/Jan/17 Resolved: 29/Mar/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 1.8.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Tom Wardrop | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
OS X 10.6.7, Mongo 1.8.0 |
||
| Issue Links: |
|
||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||
| Operating System: | OS X | ||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
I've observed that whenever the shell inserts an integer, whether it be by using a $set or an $inc in an update, or by inserting a new document, the integer gets stored in Mongo as a double. This becomes a problem when you're using the new $bit modifier as it doesn't work with doubles. I've narrowed the problem down to the Shell rather than a deeper problem, as 1.2.4 of the Ruby driver doesn't exhibit this problem. As a side issue, I'd suggest having the Shell displays doubles as such, e.g. with a trailing ".0" such as "5.0" instead of just 5. This would make it more obvious to identify such problems as this one in the future. It's only through Ruby that I can actually see that the integers being inserted by the Shell are actually doubles. |
| Comments |
| Comment by Kevin Pulo [ 25/Jan/16 ] |
|
Yes. |
| Comment by Nathan Thiya [ 06/Jan/16 ] |
|
I solved it by adding field: NumberInt(14) |
| Comment by Nathan Thiya [ 06/Jan/16 ] |
|
This problem still exists in 3.2.0-rc6. |
| Comment by Eliot Horowitz (Inactive) [ 29/Mar/11 ] |
|
The solution will be using the Integer class that I linked to. |
| Comment by Tom Wardrop [ 29/Mar/11 ] |
|
But by saying that, you're also saying that not being able to use the $bit modifier in the mongo shell - the learning and testing ground for most developers - is correct behavior? I understand that Javascript only supports one number type, but surely there's something that can be done to intelligently work around this. Could the behavior of $bit not be changed to either automatically round number, or to simply drop any form of precision? Something has to be done about this (in my opinion), at some point in the future. Just seeing the issue closed and forgotten makes me uneasy. |
| Comment by Eliot Horowitz (Inactive) [ 29/Mar/11 ] |
|
As mentioned above, numbers in javascript are doubles, so this is correct behavior. You can track |
| Comment by Scott Hernandez (Inactive) [ 27/Mar/11 ] |
|
The default numeric, and only numeric type(http://bclary.com/2004/11/07/#a-4.3.21), in javascript is a double. This is both expected and documented. It would be nice if there was more control and help within mongodb's javascript runtime. |
| Comment by Testo [ 27/Mar/11 ] |
|
similar to |