Clone button operation produces invalid EJSON when cloning documents containing a $date field.

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • No version
    • Affects Version/s: 1.48.2
    • Component/s: None
    • None
    • Environment:
      OS: Windows 11
      node.js / npm versions: N/A
      Additional info: N/A
    • Not Needed
    • None
    • Developer Tools

      Problem Statement/Rationale

      When using the Clone Document button feature in MongoDB Compass, documents containing a date field formatted as EJSON (e.g. {{{}

      { "$date": "2025-08-01T21:56:40.127Z" }

      {}}}) are incorrectly transformed. Compass duplicates the $date wrapper, producing nested $date objects.

      This causes the Insert operation to fail with the error:
      Unrecognized type for EJSON date: object

      Action requested:
      Fix the clone operation so that Compass preserves valid EJSON date structures and does not wrap $date inside another $date.

      Steps to Reproduce

      • Open a collection containing a document with a date field using EJSON format, for example:
      • {
          "name": "support",
          "cD": { "$date": "2025-08-01T21:56:40.127Z" }
        } 
      • Click Clone Document.
      • Observe the generated document in the editor.
      • Click Insert.

      Expected Results

      {
        "name": "support",
        "cD": { "$date": "2025-08-01T21:56:40.127Z" }
      }
      

      Actual Results

      {
        "name": "support",
        "cD": { "$date": { "$date": "2025-08-01T21:56:40.127Z" } }
      }
      

      Additional Notes

      • Issue appears consistently when cloning any document containing EJSON date values.
      • The problem may be related to how Compass serializes dates while rendering JSON vs EJSON modes.
      • Reproduced on a fresh install of Compass 1.48.2.

            Assignee:
            Paula Stachova
            Reporter:
            t l
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: