Skip to content

fix: preserve numeric BSON types in Document View - #1148

Open
Alok Pandey (alok-108) wants to merge 1 commit into
microsoft:mainfrom
alok-108:fix/preserve-numeric-bson-types
Open

Alok Pandey (alok-108) wants to merge 1 commit into
microsoft:mainfrom
alok-108:fix/preserve-numeric-bson-types

Conversation

@alok-108

Copy link
Copy Markdown

Fixes #1145

Problem

Document View previously read documents using the driver's default promoteValues/promoteLongs behavior and serialized/parsed them with relaxed Extended JSON (EJSON.stringify / EJSON.parse). As a result:

  • Long values (including values > 2^53) and integral Double values were written as plain JSON numbers, losing their BSON types (turning into Int32 or Double on save) and rounding 64-bit integers above 2^53.
  • Saving a document with EJSON.parse (default relaxed: true) also relaxed explicit $numberLong and integral $numberDouble wrappers back into plain numbers.

Changes

  • src/documentdb/ClustersClient.ts: Pass { promoteValues: false } to findOne in pointRead and upsertDocument so BSON numeric wrappers (Int32, Long, Double, etc.) are preserved when reading documents for Document View.
  • src/webviews/documentdb/documentView/documentEjson.ts:
    • stringifyDocumentForEditor: Keeps relaxed Extended JSON formatting for ordinary Int32 and non-integral Double values so documents remain readable, while preserving explicit $numberLong wrappers for Long and $numberDouble wrappers for integral Double values (including -0).
    • parseDocumentFromEditor: Parses editor text with EJSON.parse(documentContent, { relaxed: false }) so explicit $numberLong, $numberDouble, and $numberInt wrappers are preserved when saving.
  • src/webviews/documentdb/documentView/documentsViewRouter.ts: Use stringifyDocumentForEditor and parseDocumentFromEditor in getDocumentById and saveDocument.
  • src/webviews/documentdb/documentView/documentEjson.test.ts: Added unit tests verifying BSON round-trip preservation for Long (small and > 2^53), Double (integral, large integral, -0, fractional, NaN/Infinity), Int32, Decimal128, and ObjectId.

Verification

  • npx vitest run src/webviews/documentdb/documentView/documentEjson.test.ts src/documentdb/ClustersClient.test.ts: 46 passed (2 + 44)
  • npm run build: passed
  • npx prettier -c on the 4 changed files: passed
  • npx eslint on the 4 changed files: 0 errors

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants