From 5fb2f8a3128d312af6f470617c6c73ce132ce085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 6 Jun 2023 21:40:34 +0200 Subject: [PATCH] v0.0.139 --- wmo/queryUpdate.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wmo/queryUpdate.go b/wmo/queryUpdate.go index 19dc8b6..cca8cc9 100644 --- a/wmo/queryUpdate.go +++ b/wmo/queryUpdate.go @@ -43,3 +43,14 @@ func (c *Coll[TData]) ReplaceOne(ctx context.Context, id EntityID, value TData) return nil } + +func (c *Coll[TData]) FindOneAndReplace(ctx context.Context, id EntityID, value TData) (TData, error) { + var res TData + + err := c.coll.FindOneAndUpdate(ctx, bson.M{"_id": id}, value, options.FindOneAndUpdate().SetReturnDocument(options.After)).Decode(&res) + if err != nil { + return *new(TData), err + } + + return res, nil +}