From a30da6141927abab47b94847013dcde62fd82e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 10 Jun 2023 16:28:50 +0200 Subject: [PATCH] v0.0.158 --- goextVersion.go | 4 ++-- wmo/queryAggregate.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index be0826d..0fdb054 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.157" +const GoextVersion = "0.0.158" -const GoextVersionTimestamp = "2023-06-10T16:22:14+0200" +const GoextVersionTimestamp = "2023-06-10T16:28:50+0200" diff --git a/wmo/queryAggregate.go b/wmo/queryAggregate.go index e900751..00a747a 100644 --- a/wmo/queryAggregate.go +++ b/wmo/queryAggregate.go @@ -19,3 +19,20 @@ func (c *Coll[TData]) Aggregate(ctx context.Context, pipeline mongo.Pipeline, op return res, nil } + +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 + } + + if cursor.Next(ctx) { + v, err := c.decodeSingle(ctx, cursor) + if err != nil { + return nil, err + } + return &v, nil + } + + return nil, nil +}