Skip to content

Commit

Permalink
fix(mongox): duplicate sort key error in pagination function (#54)
Browse files Browse the repository at this point in the history
fix: duplicate sort key error in pagination function
  • Loading branch information
nourbalaha authored Nov 20, 2024
1 parent e4cc7e5 commit 4c43777
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions mongox/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/reearth/reearthx/rerror"
"github.com/reearth/reearthx/usecasex"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
Expand Down Expand Up @@ -41,11 +40,9 @@ func (c *Collection) Paginate(ctx context.Context, rawFilter any, s *usecasex.So
sortOrder *= -1
}

var sort primitive.D
if sortKey == idKey {
sort = bson.D{{Key: sortKey, Value: sortOrder}}
} else {
sort = bson.D{{Key: sortKey, Value: sortOrder}, {Key: idKey, Value: sortOrder}}
sort := bson.D{{Key: sortKey, Value: sortOrder}}
if sortKey != idKey {
sort = append(sort, bson.E{Key: idKey, Value: sortOrder})
}

findOpts := options.Find().
Expand Down

0 comments on commit 4c43777

Please sign in to comment.