Return err if cannot decode array element

v2
Nikita Tokarchuk 4 years ago
parent c019a0ea4b
commit 09fa64ab0e
  1. 11
      mongox/database/loadarray.go

@ -51,17 +51,18 @@ func (d *Database) LoadArray(target interface{}, filters ...interface{}) (err er
for i = 0; result.Next(d.Context()); { for i = 0; result.Next(d.Context()); {
if targetSliceV.Len() == i { if targetSliceV.Len() == i {
elem := reflect.New(targetSliceElemT.Elem()) elem := reflect.New(targetSliceElemT.Elem())
if err = result.Decode(elem.Interface()); err == nil { err = result.Decode(elem.Interface())
if err == nil {
targetSliceV = reflect.Append(targetSliceV, elem) targetSliceV = reflect.Append(targetSliceV, elem)
} else {
continue
} }
} else { } else {
elem := targetSliceV.Index(i).Interface() elem := targetSliceV.Index(i).Interface()
base.Reset(elem) base.Reset(elem)
if err = result.Decode(elem); err != nil { err = result.Decode(elem)
continue
} }
if err != nil {
_ = result.Close(d.Context())
return
} }
i++ i++

Loading…
Cancel
Save