Set modified via bson marshal and update operators
This commit is contained in:
@@ -2,6 +2,8 @@ package operator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"local/whodunit/storage/entity"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
@@ -51,9 +53,16 @@ func opMarshalable(op, key string, value interface{}) map[string]map[string]inte
|
||||
if len(key) == 0 {
|
||||
return nil
|
||||
}
|
||||
return map[string]map[string]interface{}{
|
||||
m := map[string]map[string]interface{}{
|
||||
op: map[string]interface{}{
|
||||
key: value,
|
||||
},
|
||||
}
|
||||
if _, ok := m["$set"]; !ok {
|
||||
m["$set"] = map[string]interface{}{}
|
||||
}
|
||||
if _, ok := m["$set"][entity.Modified]; !ok {
|
||||
m["$set"][entity.Modified] = time.Now().UnixNano()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user