v0.0.637 allow calling coll.Paginat() with limit=0 (to get only counts)
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m32s
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m32s
This commit is contained in:
+1
-1
@@ -454,7 +454,7 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CTKeySort,
|
||||
} else if token.Mode == ct.CTMEnd {
|
||||
|
||||
// false
|
||||
pipeline = append(pipeline, bson.D{{Key: "$match", Value: bson.M{"$expr": bson.M{"$eq": bson.A{"1", "0"}}}}})
|
||||
pipeline = append(pipeline, bson.D{{Key: "$match", Value: PipelineNoMatch}})
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
@@ -149,6 +149,10 @@ func (c *Coll[TData]) createPaginatedQuery(ctx context.Context, filter pag.Mongo
|
||||
pipelineList := langext.ArrConcat(pipelineFilter, pipelineSort, pipelinePaginate, extrModPipelineResolved, pipelineSort)
|
||||
pipelineTotalCount := langext.ArrConcat(pipelineFilter, pipelineCount)
|
||||
|
||||
if limit != nil && *limit <= 0 {
|
||||
pipelineList = mongo.Pipeline{bson.D{{Key: "$match", Value: PipelineNoMatch}}} // always false | return nothing
|
||||
}
|
||||
|
||||
cursorList, err := c.coll.Aggregate(ctx, pipelineList)
|
||||
if err != nil {
|
||||
return 0, nil, nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipelineList).Str("collection", c.Name()).Build()
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package wmo
|
||||
|
||||
import (
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var ObjectIDZero = langext.Must(bson.ObjectIDFromHex("000000000000000000000000"))
|
||||
|
||||
var PipelineNoMatch = bson.M{"_id": ObjectIDZero, "$expr": bson.M{"$eq": bson.A{"1", "0"}}} // always false | returns nothing
|
||||
Reference in New Issue
Block a user