Function update one now considers the protection key using the update operator

This commit is contained in:
2020-11-18 22:33:50 +01:00
parent c1ad7aea7d
commit 86397885e2
3 changed files with 30 additions and 19 deletions
+9 -6
View File
@@ -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() {