Mongo shell inserts floats instead of integers?

1,248 views
Skip to first unread message

Boris Granveaud

unread,
Jul 7, 2010, 5:10:17 AM7/7/10
to mongodb-user
Hi,

I've noticed that when I insert a document in shell, numbers are
always float even if they could be stored as integer.

For exemple:

db.test.insert({value:0});

When I load this document in Java, value is a Double. This is annoying
because my application manipulates Integer but if I insert by hand a
document to do a test, I got a Double. So I have to handle both cases
like this:

int value = ((Number) dbObject.get("value")).intValue();

not very nice....

Boris.

Michael Dirolf

unread,
Jul 7, 2010, 9:12:31 AM7/7/10
to mongod...@googlegroups.com
You should be able to use NumberLong to create an int from the shell -
this is an annoyance of JS, unfortunately:
http://jira.mongodb.org/browse/SERVER-776

> --
> 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.
>
>

Reply all
Reply to author
Forward
0 new messages