-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
5
Currently, our JavaScript test logs can contain constructor expressions for non-standard JSON types, e.g., Timestamp(1727766801, 1) or NumberLong(1). While this simplifies re-creating such objects in JavaScript environments, it often breaks external tools which expect valid JSON as input.
As a better alternative, we should return EJSON, which is already done by MongoDB server processes. For example, instead of Timestamp(1727766801, 1) return {"$timestamp": {"t": 1727766801, "i": 1}}.
The tojson() method is currently responsible for serializing constructors. The tojson() output could be used by eval() to deserialize the object. The tostrictjson() method serializes to EJSON. The mongosh shell has introduced EJSON.stringify() and EJSON.parse() for that purpose inspired by the JavaScript standard's JSON.stringify() and JSON.parse().