Set modified via bson marshal and update operators

This commit is contained in:
Bel LaPointe
2020-07-22 21:13:18 -06:00
parent 710e20d6e0
commit 9338cf86c9
4 changed files with 85 additions and 3 deletions

View File

@@ -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
}