Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-3611

Mongodump and restore should not produce a JSON format error on $-prefixed object keys

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 100.10.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • TAR 2024-07-08, TAR 2024-07-22
    • 5
    • Tools and Replicator

      Problem Statement/Rationale

      If mongodump dumps a view without an error. Mongorestore should not produce a format error when restoring the dumped file.

      Steps to Reproduce

      Create a view that has the following definition using the go driver:

      pipeline := []bson.M{
      		{"$match": bson.D{
      			{"createdAt", bson.D{
      				{"$gte", bson.D{{"$date", "2024-05-20T23:59:59Z"}}}},
      			}},
      		},
      	}
      	createCmd := bson.D{
      		{"create", "test view"},
      		{"viewOn", colName},
      		{"pipeline", pipeline},
      	}
      

      Note that the document within $gte is an object instead of a date. Both key and value are strings, but the key is "$date".

      Run mongodump and mongorestore on this view.

      Expected Results

      Mongorestore should restore the view with the same pipeline.

      Actual Results

      Mongoresture fails with an error:

      Failed: restore error: error parsing metadata from archive <file>: invalid JSON input; expected {
      

      Additional Notes

      Mongodump uses the go driver marshal function to dump a view's definition from BSON to canonical ext JSON format:

      bson.MarshalExtJSON(meta, true, false)
      

      Mongorestore does the reverse:

      bson.UnmarshalExtJSON(jsonBytes, true, meta)
      

      MarshalExtJSON marshals the format without an error, but UnmarshalExtJSON on the previously marshaled content returns the format error.

            Assignee:
            jian.guan@mongodb.com Jian Guan
            Reporter:
            jian.guan@mongodb.com Jian Guan
            Craven Huynh, Rohan Sharan
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: