mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Add filters support for a saving
This commit is contained in:
@@ -12,13 +12,15 @@ import (
|
||||
)
|
||||
|
||||
// SaveOne saves a single source document to the database
|
||||
func (d *Database) SaveOne(source interface{}) (err error) {
|
||||
func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err error) {
|
||||
|
||||
collection := d.GetCollectionOf(source)
|
||||
opts := options.FindOneAndReplace()
|
||||
id := base.GetID(source)
|
||||
protected := base.GetProtection(source)
|
||||
composed := query.Compose(bson.M{"_id": id})
|
||||
composed := query.Compose(filters...)
|
||||
|
||||
composed.And(bson.M{"_id": id})
|
||||
|
||||
opts.SetUpsert(true)
|
||||
opts.SetReturnDocument(options.After)
|
||||
|
||||
Reference in New Issue
Block a user