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