MongoDB inserts float when trying to insert integer

   > db.data.update({'name': 'zero'}, {'$set': {'value': 0}}) 
   > db.data.findOne({'name': 'zero})
    {'name': 'zero', 'value': 0.0}  

How do I get Mongo to insert an integer?

Thank you


Solution 1:

db.data.update({'name': 'zero'}, {'$set': {'value': NumberInt(0)}})

You can also use NumberLong.

Solution 2:

A slightly simpler syntax (in Robomongo at least) worked for me:

db.database.save({ Year : NumberInt(2015) });