Skip to content

Commit

Permalink
fix: support validating bson tags that have omitempty
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDufresne committed Oct 23, 2024
1 parent 771ccbc commit d106145
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 d106145

Please sign in to comment.