0

MongoDB internal data types are different for same value.

My sample document,

Ex:-

{ "val1": 120 "val2": 120 }

I am just inserting the Json data not setting any data type while inserting.

This is how I see the value in the mongo shell. But, the data types are returned as int for val1 and Double for val2.

user1578872
  • 7,808
  • 29
  • 108
  • 206
  • Does this answer your question? [MongoDB inserts float when trying to insert integer](https://stackoverflow.com/questions/8218484/mongodb-inserts-float-when-trying-to-insert-integer) So it could've happened due to some write operation on `val2` - above given link should help you know more on this issue.. – whoami - fakeFaceTrueSoul Mar 31 '20 at 00:26
  • "The mongo shell treats all numbers as floating-point values by default." (from [Data Types in the mongo Shell](https://docs.mongodb.com/manual/core/shell-types/index.html#numberlong)). If you want the data type to be specific (integer, long, fixed decimal) you must specify the data type while inserting the document. You can also check the data type of field values you have inserted; see [BSON Types](https://docs.mongodb.com/manual/reference/bson-types/index.html). – prasad_ Mar 31 '20 at 02:51

0 Answers0