Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3164

Mongo JS Driver Inserting Ints Instead of Doubles

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.5
    • Component/s: None
    • Labels:

      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.

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            john_pavlick@condenast.com John Pavlick
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: