-
Type:
Investigation
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Developer Tools
Adds new MQL expressions $serializeEJSON and $deserializeEJSON which aid conversion between BSON and Extended JSON v2.
The result of the expressions is BSON values with/without EJSON type wrappers, which can then be serialised/deserialised using $convert ($toString/$toObject) to a JSON string.
The naming and implementation is based on EJSON.serialize/deserialize methods in mongosh. Error codes and expression validation mirror those of $convert. Optional 'onError' field is available to specify error value analogously to $convert. Relaxed format is supported when serialising using an optional field 'relaxed'.
Description of Linked Ticket
This ticket is about adding support to MQL for working with Extended JSON values.
Extended JSON
The MongoDB Extended JSON is a string format for representing BSON documents.
It allows for values of BSON-only types to be represented in standard JSON.
See the specification document which contains a conversion table, mapping value representations.
Excerpt from that table:
| BSON 1.1 Type or Convention | Canonical Extended JSON Format | Relaxed Extended JSON Format |
|---|---|---|
| Int32 | {"$numberInt": }} < 32-bit signed integer as a string > { | integer |
| Int64 | {"$numberLong": }} < 64-bit signed integer as a string > { | integer |
| Double [finite] | {"$numberDouble": }} < 64-bit signed floating point as a decimal string > { | non-integer |
| Double [non-finite] | {"$numberDouble": }} < One of the strings: {{{}"Infinity", "-Infinity", or "NaN". > } | < Same as Canonical Extended JSON > |
| ... |
Existing EJSON support
The embedded JS engine does not have functions for working with EJSON.
The bson NodeJS library has support for working with EJSON.
EJSON.serialize() takes an object and transforms all native/BSON types based on the mapping defined by Extended JSON. When that object is serialized to JSON, that result is an Extended JSON string.
EJSON.deserialize() takes an object describing the structure defined by Extended JSON and transforms it into an object containing native/BSON types.
This is available in the mongosh.
Proposal
The proposal is to add MQL expressions which work similarly to these JavaScript APIs. These expressions will be able to be combined with $convert to parse JSON, transform the Extended JSON values into native BSON values and back.
- depends on
-
SERVER-107499 Support (de)serialization between BSON and EJSON
-
- Closed
-