diff --git a/bson/bson.go b/bson/bson.go index ac1c02c7f..579aec13f 100644 --- a/bson/bson.go +++ b/bson/bson.go @@ -627,7 +627,7 @@ func getStructInfo(st reflect.Type) (*structInfo, error) { inlineMap := -1 for i := 0; i != n; i++ { field := st.Field(i) - if field.PkgPath != "" { + if field.PkgPath != "" && !field.Anonymous { continue // Private field } diff --git a/bson/encode.go b/bson/encode.go index 36eb29ce6..c228e28d3 100644 --- a/bson/encode.go +++ b/bson/encode.go @@ -188,7 +188,7 @@ func isZero(v reflect.Value) bool { return v.Interface().(time.Time).IsZero() } for i := 0; i < v.NumField(); i++ { - if vt.Field(i).PkgPath != "" { + if vt.Field(i).PkgPath != "" && !vt.Field(i).Anonymous { continue // Private field } if !isZero(v.Field(i)) {