Do not print BSON with type constructors in JavaScript test logs

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • QE 2025-01-20, QE 2025-02-03, QE 2025-02-17, QE 2025-03-03
    • 5
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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().

      We might need to think about a linter rule prohibiting using tojson() within printing/output functions (print, etc) or in jstests in general.

            Assignee:
            Daniel Tabacaru
            Reporter:
            Romans Kasperovics
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: