This commit is contained in:
Mike Schwörer 2023-06-06 21:40:34 +02:00
parent 2ad820be8d
commit 5fb2f8a312
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

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