Rounding long values?

107 views
Skip to first unread message

Justo

unread,
Nov 26, 2009, 1:21:46 PM11/26/09
to mongodb-user
Hi,

I've come across an odd issue with long numbers being rounded on
version 1.0.1; I've haven't tried in a different version.

The script I am executing (using the interactive console) is as
follows:

> testCol = db.TestCol
test.TestCol
> testCol.save( {aNumber: 123456789012345678})
> testCol.find()
{"_id" : ObjectId( "4b0ec649af0e000000001492") , "aNumber" :
123456789012345680}

As you can see, aNumber has being rounded upwards. If I now carry on
executing the following...

> testCol.save ({aNumber: 123456789012345672})
> testCol.find()
{"_id" : ObjectId( "4b0ec649af0e000000001492") , "aNumber" :
123456789012345680}
{"_id" : ObjectId( "4b0ec6a2af0e000000001493") , "aNumber" :
123456789012345660}

... it gets rounded to 60!!

Am I doing anything wrong?

Thanks a lot!!


Dwight Merriman

unread,
Nov 26, 2009, 1:52:25 PM11/26/09
to mongod...@googlegroups.com
the problem is that in the shell (which is javascript based) number is being stored as a double type and double's can represent  a  number that large uniquely.  from the stock spidermonkey shell:

js> x = 123456789012345678
123456789012345680

now you can use the longint type which mongodb supports (see the BSON page).  the way to store that varies by driver and i'm not sure how to do it from the shell.  what language are you coding in?




--

You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.



Justo Ruiz

unread,
Nov 26, 2009, 2:02:41 PM11/26/09
to mongod...@googlegroups.com
We are coding in C#.  

The reason we run that test on the shell console was triggered because we saw the same behaviour when sending long values from our libraries.  We have written our own "driver" because the reference drivers (the ones available on the net) are very slow.  

We have develop a c# native BSON document generator that matches better our serialization needs.

I should be trying the same using a different driver language and I'll let you know the results.

Thanks for the quick response.

Justo.




2009/11/26 Dwight Merriman <dwi...@10gen.com>

Justo Ruiz

unread,
Nov 26, 2009, 2:20:07 PM11/26/09
to mongod...@googlegroups.com
Yep.  You are right.  The Java driver doesn't seem to have such issue. 

Thanks

Justo.

2009/11/26 Justo Ruiz <justo...@gmail.com>

Dwight Merriman

unread,
Nov 26, 2009, 5:21:12 PM11/26/09
to mongod...@googlegroups.com
ok - i don't know the c# driver well as it is community supported.  perhaps a small extension of it would solve the problem if you feel so inclined
Reply all
Reply to author
Forward
0 new messages