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 there a way in the mongo js driver to force it to always store numbers as doubles? I am ultimately reading this into a Java program which really wants the incoming types to be consistent, so if I can make them that way on insert I'd like to do that.