added mongo-driver v2
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m33s

This commit is contained in:
2026-04-21 18:41:32 +02:00
parent f62e7499ec
commit 26d542c9a2
33 changed files with 205 additions and 522 deletions
+16 -14
View File
@@ -2,12 +2,13 @@ package wmo
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"iter"
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
"iter"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
func (c *Coll[TData]) createFindQuery(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (*mongo.Cursor, error) {
@@ -51,7 +52,7 @@ func (c *Coll[TData]) createFindQuery(ctx context.Context, filter bson.M, opts .
}
}
convOpts := make([]*options.AggregateOptions, 0, len(opts))
convOpts := make([]*options.AggregateOptionsBuilder, 0, len(opts))
for _, v := range opts {
vConv, err := convertFindOpt(v)
if err != nil {
@@ -60,7 +61,14 @@ func (c *Coll[TData]) createFindQuery(ctx context.Context, filter bson.M, opts .
convOpts = append(convOpts, vConv)
}
cursor, err := c.coll.Aggregate(ctx, pipeline, convOpts...)
convOptsLister := make([]options.Lister[options.AggregateOptions], 0, len(convOpts))
for _, v := range convOpts {
if v != nil {
convOptsLister = append(convOptsLister, v)
}
}
cursor, err := c.coll.Aggregate(ctx, pipeline, convOptsLister...)
if err != nil {
return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
}
@@ -137,7 +145,7 @@ func (c *Coll[TData]) FindIterate(ctx context.Context, filter bson.M, opts ...*o
}
// converts FindOptions to AggregateOptions
func convertFindOpt(v *options.FindOptions) (*options.AggregateOptions, error) {
func convertFindOpt(v *options.FindOptions) (*options.AggregateOptionsBuilder, error) {
if v == nil {
return nil, nil
}
@@ -157,7 +165,7 @@ func convertFindOpt(v *options.FindOptions) (*options.AggregateOptions, error) {
r.SetCollation(v.Collation)
}
if v.Comment != nil {
r.SetComment(*v.Comment)
r.SetComment(v.Comment)
}
if v.CursorType != nil {
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'CursorType' (cannot convert to AggregateOptions)").Build()
@@ -171,9 +179,6 @@ func convertFindOpt(v *options.FindOptions) (*options.AggregateOptions, error) {
if v.MaxAwaitTime != nil {
r.SetMaxAwaitTime(*v.MaxAwaitTime)
}
if v.MaxTime != nil {
r.SetMaxTime(*v.MaxTime)
}
if v.Min != nil {
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'Min' (cannot convert to AggregateOptions)").Build()
}
@@ -189,9 +194,6 @@ func convertFindOpt(v *options.FindOptions) (*options.AggregateOptions, error) {
if v.ShowRecordID != nil {
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'ShowRecordID' (cannot convert to AggregateOptions)").Build()
}
if v.Snapshot != nil {
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'Snapshot' (cannot convert to AggregateOptions)").Build()
}
if v.Let != nil {
r.SetLet(v.Let)
}