-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.6.5
-
Component/s: None
-
Empty show more show less
I'm using the Mongo Native Javascript driver to insert data into a Mongo database. All of the docs I've read say that Mongo stores all of its numeric values as Doubles, and Javascript also stores all of its numerics as doubles. I can confirm that this works in the shell:
PRIMARY> db.products.insertOne({id: 10, price: 10})
PRIMARY> db.products.insertOne({id: 11, price: 11.99})
PRIMARY> db.products.aggregate([\{$project: { price: {$type: "$price"}}}])
{ "_id" : ObjectId("605525ed8f87f3c9bc136a69"), "price" : "double" }
{ "_id" : ObjectId("605525fb8f87f3c9bc136a6a"), "price" : "double" }
However, when I insert values from the Javascript driver, they are not all doubles, but instead the integer-looking number is stored with a bsontype of int:
-- Node
await products.insertOne({id: 1, price: 20});
await products.insertOne({id: 2, price: 20.85});
--Mongo Shell
PRIMARY> db.products.aggregate([\{$project: { price: {$type: "$price"}}}])
{ "_id" : ObjectId("6055261ee2efe2622736a36e"), "price" : "int" }
{ "_id" : ObjectId("6055261ee2efe2622736a36f"), "price" : "double" }
Is this expected behavior for the driver? Sorry if this isn't actually a bug, I just couldn't find anything in the docs that indicated the JS driver would do implicit casting of values before insert.
- is related to
-
MONGOSH-602 Numeric values are stored as Int32 instead of Double
- Closed
-
NODE-4948 Spike: Investigate defaulting javascript numbers to doubles in BSON serialize and EJSON stringify
- Blocked
-
NODE-4946 Cast Javascript Number as bsonType: "double"
- Blocked