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 +}