[SERVER-64] Ints are converted to Float in Javascript Created: 21/May/09  Updated: 02/Nov/09  Resolved: 21/May/09

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 0.9.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Yun Huang Yong Assignee: Eliot Horowitz (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Self-built Linux 64-bit, current to master head:
Fri May 22 02:45:00 git version: 87372071fca2cd49a67085bc80d1c1a3fb9b2202

Running latest Ruby driver, also built from latest git: dc44751d2fb18a8be1f301ecac24e675d4da2b0e


Attachments: File javascript_numbers.rb    
Participants:

 Description   

When integers are inserted using javascript either in the Mongo shell, or using db.eval(), they seem to be converted to Floats.

In the attached Ruby code the db.eval() created document has converted the integer 1 value into a float 1 value.

Similarly, if you insert a

{ "test" : 1 }

document from Mongo shell, and then retrieve it using the Ruby driver it comes back as a Float 1.0.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 21/May/09 ]

Yeah - the java javascript engine did some weird things with numbers.

We could do something to preserve types across.

I'll make a new case for that

Comment by Yun Huang Yong [ 21/May/09 ]

Hmmm, I only noticed this because using the db.eval() to copy objects from one collection to another, you would expect that the copied collection has exactly the same data (and type) as the original.

Its weird that I can insert a Ruby Fixnum 1, run the db.eval() copy, then retrieve a Float 1.0.

This wasn't the case on the previous nightly I was running (from 4th May).

Comment by Eliot Horowitz (Inactive) [ 21/May/09 ]

all numbers in javascript are floats - so if you use db.eval everything will be a float.

i guess we could add some hacky thing in javascript to get you integers - but would be working around javascript.

if this is something you require - let us know

Generated at Thu Feb 08 02:52:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.