Fix broken filtering through discriminator

This commit is contained in:
George Suntres
2026-04-17 20:46:00 -04:00
parent 99b36e577e
commit 7599b8b856
7 changed files with 30 additions and 11 deletions

11
find.go
View File

@@ -4,6 +4,7 @@ import (
"context"
"go.mongodb.org/mongo-driver/v2/bson"
"git.gsuntres.com/general/commons"
)
// Find is used to fetch the first page of data.
@@ -89,10 +90,14 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
finalLimit := max(limit, c.Limit)
if err := c.DiscriminatorCheckAndApplyToFilter(ctx, name, filter); err != nil {
return nil, err
}
f := Mongofy(&Query{
Filter: filter,
})
pipeline := BuildPaginationPipeline(offset, finalLimit, f, nil)
// 2. Query
@@ -116,8 +121,8 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
var totalValue any
if len(metadata) != 0 {
metadataRoot := metadata[0].(bson.M)
totalValue = metadataRoot["total"]
metadataRoot := metadata[0].(bson.D)
totalValue, _ = commons.BsonDGetAny(metadataRoot, "total")
}
var total int64