From a49dc735e97701d6beee03687dc63e6bccca0691 Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Tue, 19 Feb 2019 18:18:34 +0100 Subject: [PATCH] Fix loadarray slice offset --- mongox/common/loadarray.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mongox/common/loadarray.go b/mongox/common/loadarray.go index fd5eb44..b7ce0c2 100644 --- a/mongox/common/loadarray.go +++ b/mongox/common/loadarray.go @@ -48,19 +48,17 @@ func LoadArray(db *mongox.Database, target interface{}, filters ...interface{}) defer result.Close(db.Context()) var i int - for i = 0; result.Next(db.Context()); i++ { + for i = 0; result.Next(db.Context()); { if targetSliceV.Len() == i { elem := reflect.New(targetSliceElemT.Elem()) if result.Decode(elem.Interface()) != nil { - continue + targetSliceV = reflect.Append(targetSliceV, elem) } - - targetSliceV = reflect.Append(targetSliceV, elem) - // currentv = currentv.Slice(0, currentv.Cap()) - continue + } else { + result.Decode(targetSliceV.Index(i).Interface()) } - result.Decode(targetSliceV.Index(i).Interface()) + i++ } targetSliceV = targetSliceV.Slice(0, i)