mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-07-03 17:22:33 +00:00
Return err if cannot decode array element
This commit is contained in:
@@ -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++
|
||||||
|
|||||||
Reference in New Issue
Block a user