Mike Schwörer
f3ecba3883
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m22s
30 lines
789 B
Go
30 lines
789 B
Go
package wmo
|
|
|
|
import (
|
|
"context"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
|
)
|
|
|
|
func (c *Coll[TData]) Find(ctx context.Context, filter bson.M) ([]TData, error) {
|
|
|
|
pipeline := mongo.Pipeline{}
|
|
pipeline = append(pipeline, bson.D{{Key: "$match", Value: filter}})
|
|
|
|
pipeline = langext.ArrConcat(pipeline, c.extraModPipeline)
|
|
|
|
cursor, err := c.coll.Aggregate(ctx, pipeline)
|
|
if err != nil {
|
|
return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
|
}
|
|
|
|
res, err := c.decodeAll(ctx, cursor)
|
|
if err != nil {
|
|
return nil, exerr.Wrap(err, "failed to decode values").Build()
|
|
}
|
|
|
|
return res, nil
|
|
}
|