v0.0.248 exerr in wmo package
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 55s
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 55s
This commit is contained in:
@@ -2,20 +2,20 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
||||
)
|
||||
|
||||
func (c *Coll[TData]) Aggregate(ctx context.Context, pipeline mongo.Pipeline, opts ...*options.AggregateOptions) ([]TData, error) {
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Any("options", opts).Str("collection", c.Name()).Build()
|
||||
}
|
||||
|
||||
res, err := c.decodeAll(ctx, cursor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "failed to decode values").Build()
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -24,13 +24,13 @@ func (c *Coll[TData]) Aggregate(ctx context.Context, pipeline mongo.Pipeline, op
|
||||
func (c *Coll[TData]) AggregateOneOpt(ctx context.Context, pipeline mongo.Pipeline, opts ...*options.AggregateOptions) (*TData, error) {
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Any("options", opts).Str("collection", c.Name()).Build()
|
||||
}
|
||||
|
||||
if cursor.Next(ctx) {
|
||||
v, err := c.decodeSingle(ctx, cursor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "failed to decode single value").Build()
|
||||
}
|
||||
return &v, nil
|
||||
}
|
||||
@@ -41,16 +41,16 @@ func (c *Coll[TData]) AggregateOneOpt(ctx context.Context, pipeline mongo.Pipeli
|
||||
func (c *Coll[TData]) AggregateOne(ctx context.Context, pipeline mongo.Pipeline, opts ...*options.AggregateOptions) (TData, error) {
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline, opts...)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
return *new(TData), exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Any("options", opts).Str("collection", c.Name()).Build()
|
||||
}
|
||||
|
||||
if cursor.Next(ctx) {
|
||||
v, err := c.decodeSingle(ctx, cursor)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
return *new(TData), exerr.Wrap(err, "failed to decode single value").Build()
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
return *new(TData), errors.New("no document in result")
|
||||
return *new(TData), exerr.Wrap(mongo.ErrNoDocuments, "no document in result").Build()
|
||||
}
|
||||
|
Reference in New Issue
Block a user