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
    • Labels:

      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.

            Unassigned Unassigned
            david.golden@mongodb.com David Golden
            3 Vote for this issue
            11 Start watching this issue