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

fix(Decimal128): throw error when passing a string to Decimal128 constructor

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON

      https://github.com/mongodb/js-bson/pull/322

      You can get some nasty surprises when you pass a string to the Decimal128 constructor:

      const bson = require('bson');
      
      const v = new bson.Decimal128('14.92');
      
      // {"$numberDecimal":"8.740930561E-6167"}
      console.log(JSON.stringify(v));
      

      Would be handy to at least throw an error. Although is there some reason why we can't just do fromString() if the user passes a string instead of a buffer to the Decimal128 constructor?

            Assignee:
            Unassigned Unassigned
            Reporter:
            alexander.golin@mongodb.com Alexander Golin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: