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

Spike: Investigate defaulting javascript numbers to doubles in BSON serialize and EJSON stringify

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

      Use Case

      As a javascript user
      I want javascript numbers to remain doubles when serialized
      So that even integer-like doubles do not get converted to int32s

      User Impact

      • JS numbers that are integers and are within an int32 range are serialized as int32
        • This leads to behavior like: c.insertOne({ a: 1.7 + 0.3 }), a becoming an int32 here because the arithmetic resulted in a small integer-like value.
      • If BSON were to always use doubles it would increase the default storage usage for numbers.
      • MongoDB has flexible number comparison, generally lookups are not impacted by numbers changing type information.

      Dependencies

      • NODE-4780: promoteValues is the opposite side of the problem here, if enabled the flag will return Double instances, this can be useful for preserving the roundtrip type information

      Unknowns

      • How would serializing JS numbers to doubles with either a flag or by default impact the driver's messages to the server? (Non-user data, hellos, etc.)

      Acceptance Criteria

      Implementation Requirements

      • Write up a document with investigation findings.

      Follow Up Requirements

      • Downstream impacts; Does mongosh want to offer or adopt this flag to offer legacy shell behavior. What granularity is necessary?

            Assignee:
            Unassigned Unassigned
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: