This commit is contained in:
Mike Schwörer 2023-06-07 17:57:03 +02:00
parent 0006c6859d
commit 6589e8d5cd
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 9 additions and 6 deletions

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.150" const GoextVersion = "0.0.151"
const GoextVersionTimestamp = "2023-06-07T17:48:36+0200" const GoextVersionTimestamp = "2023-06-07T17:57:03+0200"

View File

@ -69,7 +69,7 @@ func CreatePagination[TData any](coll *Coll[TData], token ct.CursorToken, fieldP
} else if token.Mode == ct.CTMEnd { } else if token.Mode == ct.CTMEnd {
// false // false
pipeline = append(pipeline, bson.D{{Key: "$match", Value: bson.M{"$eq": bson.A{"1", "0"}}}}) pipeline = append(pipeline, bson.D{{Key: "$match", Value: bson.M{"$expr": bson.M{"$eq": bson.A{"1", "0"}}}}})
} else { } else {

View File

@ -37,7 +37,7 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
return nil, ct.CursorToken{}, err return nil, ct.CursorToken{}, err
} }
entities := make([]TData, 0, cursor.RemainingBatchLength()+1) entities := make([]TData, 0, cursor.RemainingBatchLength())
for (pageSize == nil || len(entities) != *pageSize) && cursor.Next(ctx) { for (pageSize == nil || len(entities) != *pageSize) && cursor.Next(ctx) {
var entry TData var entry TData
err = cursor.Decode(&entry) err = cursor.Decode(&entry)
@ -47,13 +47,16 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
entities = append(entities, entry) entities = append(entities, entry)
} }
if pageSize == nil || len(entities) <= *pageSize || !cursor.TryNext(ctx) { if pageSize == nil || len(entities) < *pageSize || !cursor.TryNext(ctx) {
return entities, ct.End(), nil return entities, ct.End(), nil
} }
last := entities[len(entities)-1] last := entities[len(entities)-1]
nextToken, _ := c.createToken(sortPrimary, sortDirPrimary, sortSecondary, sortDirSecondary, last, pageSize) nextToken, err := c.createToken(sortPrimary, sortDirPrimary, sortSecondary, sortDirSecondary, last, pageSize)
if err != nil {
return nil, ct.CursorToken{}, err
}
return entities, nextToken, nil return entities, nextToken, nil
} }