Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-96709

Do not print BSON with type constructors in JavaScript test logs

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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().

            Assignee:
            Unassigned Unassigned
            Reporter:
            romans.kasperovics@mongodb.com Romans Kasperovics
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: