v0.0.151
This commit is contained in:
@@ -69,7 +69,7 @@ func CreatePagination[TData any](coll *Coll[TData], token ct.CursorToken, fieldP
|
||||
} else if token.Mode == ct.CTMEnd {
|
||||
|
||||
// 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 {
|
||||
|
||||
|
@@ -37,7 +37,7 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
|
||||
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) {
|
||||
var entry TData
|
||||
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)
|
||||
}
|
||||
|
||||
if pageSize == nil || len(entities) <= *pageSize || !cursor.TryNext(ctx) {
|
||||
if pageSize == nil || len(entities) < *pageSize || !cursor.TryNext(ctx) {
|
||||
return entities, ct.End(), nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user