v0.0.448 wmo marshalHook
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 25s

This commit is contained in:
2024-05-12 16:45:45 +02:00
parent 631006a4e1
commit fe4cdc48af
4 changed files with 35 additions and 2 deletions

View File

@@ -61,6 +61,10 @@ func (c *Coll[TData]) UpdateMany(ctx context.Context, filterQuery bson.M, update
}
func (c *Coll[TData]) ReplaceOne(ctx context.Context, filterQuery bson.M, value TData) error {
for _, hook := range c.marshalHooks {
value = hook(value)
}
_, err := c.coll.UpdateOne(ctx, filterQuery, bson.M{"$set": value})
if err != nil {
return exerr.Wrap(err, "mongo-query[replace-one] failed").
@@ -73,6 +77,10 @@ func (c *Coll[TData]) ReplaceOne(ctx context.Context, filterQuery bson.M, value
}
func (c *Coll[TData]) FindOneAndReplace(ctx context.Context, filterQuery bson.M, value TData) (TData, error) {
for _, hook := range c.marshalHooks {
value = hook(value)
}
mongoRes := c.coll.FindOneAndReplace(ctx, filterQuery, value, options.FindOneAndReplace().SetReturnDocument(options.After))
if err := mongoRes.Err(); err != nil {
return *new(TData), exerr.Wrap(err, "mongo-query[find-one-and-update] failed").