Add UpdateSet, Relaxed in client, Fix tests

This commit is contained in:
George Suntres
2026-04-22 10:22:23 -04:00
parent 45f9ac558f
commit 188c5a1be1
9 changed files with 163 additions and 31 deletions

21
find.go
View File

@@ -37,7 +37,11 @@ func (c *MongoClient) Find(ctx context.Context, database, name string, filter bs
return nil, err
}
pipeline := BuildPaginationPipeline(0, pageSize + 1, filter, sort)
f := Mongofy(&Query{
Filter: filter,
})
pipeline := BuildPaginationPipeline(0, pageSize + 1, f, sort)
// 2. Query
cursor, err := collection.Aggregate(ctx, pipeline)
@@ -114,6 +118,10 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
limit = opts.Limit
}
if opts != nil {
offset = opts.Offset
}
// 1. Prepare to query.
finalName := name
if opts != nil && commons.StringIsNotBlank(opts.Alias) {
@@ -130,7 +138,7 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
f := Mongofy(&Query{
Filter: filter,
})
pipeline := BuildPaginationPipeline(offset, finalLimit, f, nil)
// 2. Query
@@ -175,9 +183,13 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
}
hasMore := false
if int64(len(data)) > finalLimit {
if total > offset + finalLimit {
hasMore = true
data = data[:finalLimit]
}
hasPrevious := false
if finalLimit - offset < 0 {
hasPrevious = true
}
out := bson.M{
@@ -185,6 +197,7 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
"offset": offset,
"limit": finalLimit,
"has_more": hasMore,
"has_previous": hasPrevious,
"total": total,
}