mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Add context support to a saving
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user