From d106145d7e06558540aed31c2939cab04cfe57cc Mon Sep 17 00:00:00 2001 From: Etienne Dufresne Date: Wed, 23 Oct 2024 08:48:14 -0400 Subject: [PATCH] fix: support validating bson tags that have omitempty --- mongo/find.go | 6 +++++- mongo/find_test.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mongo/find.go b/mongo/find.go index e55d2f0..6a57930 100644 --- a/mongo/find.go +++ b/mongo/find.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "reflect" + "strings" "time" mcpbson "github.com/qlik-oss/mongocursorpagination/bson" @@ -483,7 +484,10 @@ func validate(results interface{}, paginatedFields []string) error { field := elem.Field(i) tag := field.Tag.Get("bson") - if tag == paginatedField { + tagParts := strings.Split(tag, ",") + fieldName := strings.TrimSpace(tagParts[0]) + + if fieldName == paginatedField { paginatedFieldFound = true break } diff --git a/mongo/find_test.go b/mongo/find_test.go index 618a810..0465cad 100644 --- a/mongo/find_test.go +++ b/mongo/find_test.go @@ -13,7 +13,7 @@ type ( Item struct { ID primitive.ObjectID `bson:"_id"` Name string `bson:"name"` - Data string `bson:"data"` + Data string `bson:"data,omitempty"` CreatedAt time.Time `bson:"createdAt"` } )