how to insert int instead of float?

54 views
Skip to first unread message

mithril

unread,
Oct 10, 2015, 5:17:24 PM10/10/15
to mongodb-user
at title says,


db.test.insert({'artist': 'xxx', 'count':1});

always insert 'count' as float

Stephen Steneker

unread,
Oct 10, 2015, 5:27:19 PM10/10/15
to mongodb-user

On Sunday, 11 October 2015 08:17:24 UTC+11, mithril wrote:


db.test.insert({'artist': 'xxx', 'count':1});

always insert 'count' as float

Hi,

JavaScript only has a single numeric type (Number) which is always a 64-bit floating point value.

The mongo shell has helper functions NumberInt() and NumberLong() to allow you to work with 32-bit and 64-bit integers respectively:

    db.test.insert({'artist': 'xxx', 'count': NumberInt(1)});
    db.test.insert({'artist': 'xxx', 'count': NumberLong(1)});

See Data Types in the mongo Shell in the MongoDB manual for more information.

Regards,
Stephen

mithril

unread,
Oct 11, 2015, 2:08:54 AM10/11/15
to mongodb-user
 Chrome console show 1 just 1, that make me consider Javascript has int type before. Thank you!
Reply all
Reply to author
Forward
0 new messages