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

"lax" mode for BSON decoding like mgo/bson

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None

      In porting mongotop to the new driver, I discovered a subtle incompatibility.  The top command returns a document like this:

      {
              "totals" : {
                      "note" : "all times in microseconds",
                      "admin.system.roles" : { ... },
                      "admin.system.version" : { ... },
                      ...
              }
      }
      

      mongotop wants to decode that into a type like this:

      type Top struct {
          Totals map[string]NSTopInfo `bson:"totals"`
      }
      

      The problem is that the 'note' field is a string, not a document, so can't be decoded to a "NSTopInfo" struct. mgo's Unmarshal behavior is: "if the value would not fit the type and cannot be converted, it's silently skipped", so with mgo, the 'note' field was ignored.

      The Go driver is strict – and errors on the 'note' field. On the one hand, this is correct behavior, but on the other hand it may cause surprising and subtle user pain converting from mgo where irregular structures like the 'top' output could be handled more seamlessly.

      I have no strong feelings one way or another, but thought there should be some discussion of whether/how to address or avoid this user pain.

            Assignee:
            isabella.siu@mongodb.com Isabella Siu (Inactive)
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: