Skip to content

#grid Document View changes numeric BSON types on save (Long and Double become Int32) #rdg #1145

Backlog

Description

Summary

Document View can change numeric BSON types when a document is saved, and it can display a wrong value for a 64-bit integer above 2^53. Found while reviewing #1142; it predates that PR and is outside its scope.

Cause

  • Document View reads the document with relaxed Extended JSON: EJSON.stringify(...) in getDocumentById (src/webviews/documentdb/documentView/documentsViewRouter.ts:67).
  • It saves with relaxed parsing: EJSON.parse(input.documentContent) in saveDocument (documentsViewRouter.ts:81).
  • The driver's default promoteLongs / promoteValues are in effect; no read options are set.

Relaxed Extended JSON writes numbers as plain JSON numbers, so the editor text no longer carries the BSON type, and relaxed parsing picks a type from the number's value.

Evidence

An offline simulation of that read → edit → save path with the installed bson 7.2.0 (driver mongodb 7.2.0) gave:

Field Stored Shown in the editor Saved as
small Long 5 5 Int32 5
big Long 9007199254740993 9007199254740992 Double 9007199254740992
dbl Double 1 1 Int32 1
i32 Int32 7 7 Int32 7 (unchanged)

Not reproduced against a live server; the server stores whatever the driver sends.

Impact

  • Saving a document without touching a numeric field can still change that field's BSON type (Long → Int32, integral Double → Int32).
  • A Long above 2^53 is displayed with a wrong value and saved as a rounded Double.

Options

  1. Read with promoteValues: false and keep explicit type wrappers only where relaxed output would lose information (Long, integral Double), so ordinary numbers stay readable. More code, but exact and readable.
  2. Use canonical Extended JSON in both directions. Exact, and a small change, but every number shows as {"$numberInt": "7"} in the editor.
  3. Won't fix. Silent type changes remain.

Option 1 is the current recommendation.

Related

Activity

  1. added
    bug
    on Nov 27, 2026
  2. changed the title [-]Document View changes numeric BSON types on save (Long and Double become Int32)[/-] [+]#grid Document View changes numeric BSON types on save (Long and Double become Int32)[/+] on Dec 1, 2026
  3. tnaum-ms commented on Dec 1, 2026

    @tnaum-ms
    CollaboratorAuthor

    The separate implementation PR is #1148 (target: main); merging #1142 is not evidence that Document View numeric round-tripping is fixed. Keep acceptance for an untouched small Long, a Long above 2^53, and an integral Double, checking both the value and stored BSON type after save. The falsy _id fix in the migration and insert-only Add in #1153 have different causes. These distinctions also matter before any inline editing under #62.

  4. changed the title [-]#grid Document View changes numeric BSON types on save (Long and Double become Int32)[/-] [+]#grid Document View changes numeric BSON types on save (Long and Double become Int32) #rdg[/+] on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions