From bf1dad5a22a19a28a65d78c02af610dbece2d4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 26 Mar 2025 23:25:44 -0400 Subject: [PATCH] fix `doSave` calls to check if the document's ID is a zero value --- document.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/document.go b/document.go index 7824d25..dfd97fe 100644 --- a/document.go +++ b/document.go @@ -96,13 +96,15 @@ func (d *Document) Save() error { if val.Kind() == reflect.Slice { for i := 0; i < val.Len(); i++ { cur := val.Index(i) - if err := doSave(d.model.getColl(), !d.exists, cur.Interface()); err != nil { + asId := cur.Interface().(HasID) + if err := doSave(d.model.getColl(), !d.exists && reflect.ValueOf(asId.Id()).IsZero(), cur.Interface()); err != nil { return err } } return nil } else { - return doSave(d.model.getColl(), !d.exists, d.self) + asId := val.Interface().(HasID) + return doSave(d.model.getColl(), !d.exists && reflect.ValueOf(asId.Id()).IsZero(), d.self) } }