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

Document interface{} unmarshalling behavior

    • Type: Icon: Task Task
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • 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?

      EDIT: The resolution for this ticket is that we should document that unmarshalling into a struct that has a field with type interface{} yields a bson.D. This differs from mgo, which defaulted to bson.M.

       

       

      if we have a struct like 

       

      type Something struct {
         Val []interface `bson="val"`
      }
      

      In our case this struct is an array of objects. It was actually just a draftJS block. in JSON it would look like this, and this is what it would look like after being inserted into mongo

      [{
        "entityRanges" : [ ],
        "inlineStyleRanges" : [ ],
        "key" : "fb86k",
        "text" : "",
        "type" : "unstyled"
      }]

       

      the mongo driver marshalled this perfectly into the database. No issues there. However when pulling the data out, we receive 

      [
        {Key: "entityRanges", Value: [ ]},
        {Key: "inlineStyleRanges", Value: [ ]},
        {Key: "key", Value: "fb86k"},
        {Key: "type", Value: "unstyled"},
      
      ]

      this doesn't reflect the data in the database and actually makes no sense why mongo decided to break up the object like this

            Assignee:
            Unassigned Unassigned
            Reporter:
            qhenkart@launchpadcentral.com Quest Henkart
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: