Add context support to a saving

v2
Nikita Tokarchuk 4 years ago
parent 28be1f46b9
commit 06f6f48f11
  1. 3
      mongox/database/saveone.go

@ -19,6 +19,7 @@ func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err erro
id := base.GetID(source)
protected := base.GetProtection(source)
composed := query.Compose(filters...)
ctx := query.WithContext(d.Context(), composed)
composed.And(bson.M{"_id": id})
@ -31,7 +32,7 @@ func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err erro
protected.V = time.Now().Unix()
}
result := collection.FindOneAndReplace(d.Context(), composed.M(), source, opts)
result := collection.FindOneAndReplace(ctx, composed.M(), source, opts)
if result.Err() != nil {
return result.Err()
}

Loading…
Cancel
Save