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

Document decoding to empty interface

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Documentation
    • 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?

      A Reddit question about decoding SingleResult suggests that the driver will successfully decode into an empty interface variable.

      func GetMonthStatusByID(ctx context.Context, id string) (interface{}, error) {
          var monthStatus interface{}
          filter := bson.M{"_id": id}
          err := db.Collection("Months").FindOne(ctx, filter).Decode(&monthStatus)
          return monthStatus, err
      }
      

      It looks like the result might have been a primative.D.

      On one hand, this sort of makes sense because any type will satisfy the empty interface. OTOH, it's probably a user being misled by the type signature, as there's no real use for decoding to empty interface versus a concrete type or an Unmarshaler interface.

      I think it should either error, on the grounds that users probably made a mistake, or else we should document the behavior to indicate that decoding to empty interface defaults to primative.D.

            Assignee:
            Unassigned Unassigned
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            3 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: