always insert int value

孟犁 shared this problem 21 months ago
Solved

db.test.insert({number: 1}): insert `number` as int32, but it should be a double value

Comments (2)

photo
1

Yes, the mongo shell always treats a number as double. MongoDB Nodejs Driver will be smarter to select data types. if you insert '1', it will be an Int32, if you insert '1.1', it will be a double. Currently, NoSQLBooster uses MongoDB's NodeJS driver solution, so you'll see if you insert "1", you'll get an Int32 value "1", not a double value.


I think Nodejs driver's solution is better, MongoDB driver in other languages is similar to NodeJS. This does create inconsistencies with the implementation of mongo shell. I put this question on hold for the time being, and I want to hear more people's opinions.


If you want to insert a double value "1", please use the Double(1).


db.test.insert({number: Double(1)})

photo
1

Resolved in 5.0.0, In the v5, always treats a number as double.