mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Function update one now considers the protection key using the update operator
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/modern-go/reflect2"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
@@ -32,13 +33,15 @@ func (d *Database) UpdateOne(target interface{}, filters ...interface{}) (err er
|
||||
if !protected.X.IsZero() {
|
||||
query.Push(composed, protected)
|
||||
}
|
||||
//updater = append(updater, primitive.M{
|
||||
// "$set": primitive.M{
|
||||
// "_x": primitive.NewObjectID(),
|
||||
// "_v": time.Now().Unix(),
|
||||
// },
|
||||
//})
|
||||
|
||||
protected.Restate()
|
||||
|
||||
setCmd, _ := updaterDoc["$set"].(primitive.M)
|
||||
if reflect2.IsNil(setCmd) {
|
||||
setCmd = primitive.M{}
|
||||
}
|
||||
protected.PutToDocument(setCmd)
|
||||
updaterDoc["$set"] = setCmd
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user