Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-3273

Marshaling and unmarshaling should not produce a JSON format error on $-prefixed object keys

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Go Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Detailed steps to reproduce the problem?

      1. Create a document that both key and value are strings, but the key is "$date".
        bson.D{{"$date", "2024-05-20T23:59:59Z"}}
        
      2. Marshaling the object to canonical extended JSON succeeds
        bson.MarshalExtJSON(doc, true, false)
        
      3. Unmarshaling the JSON back to BSON
        bson.UnmarshalExtJSON(jsonBytes, true, meta)
        

        It returns an error.

        invalid JSON input; expected {
        

      Definition of done: what must be done to consider the task complete?

      We expect that marshaling from BSON to canonical extended JSON is reversible through unmarshaling using the go driver. If marshaling succeeds, unmarshaling should produce the original BSON document without an error. Mongodump and mongorestore rely on this assumption to perform database backups correctly.

      The exact Go version used, with patch level:

      1.21

      The exact version of the Go driver used:

      v1.11.9

            Assignee:
            Unassigned Unassigned
            Reporter:
            jian.guan@mongodb.com Jian Guan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: