Skip to content

Commit

Permalink
Merge pull request #46 from qlik-oss/euf/complex-bson-tags
Browse files Browse the repository at this point in the history
fix: support validating bson tags that have omitempty
  • Loading branch information
EtienneDufresne authored Oct 23, 2024
2 parents 771ccbc + d106145 commit 7844ea7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mongo/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"reflect"
"strings"
"time"

mcpbson "github.com/qlik-oss/mongocursorpagination/bson"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion mongo/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)
Expand Down

0 comments on commit 7844ea7

Please sign in to comment.