New API tested
This commit is contained in:
@@ -23,6 +23,14 @@ func (pi PopIf) MarshalBSON() ([]byte, error) {
|
||||
return opMarshal("$pull", pi.Key, pi.Filter)
|
||||
}
|
||||
|
||||
type SetMany struct {
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (s SetMany) MarshalBSON() ([]byte, error) {
|
||||
return opMarshal("$set", "", s.Value)
|
||||
}
|
||||
|
||||
type Set struct {
|
||||
Key string
|
||||
Value interface{}
|
||||
@@ -49,20 +57,28 @@ func opMarshal(op, key string, value interface{}) ([]byte, error) {
|
||||
return bson.Marshal(marshalable)
|
||||
}
|
||||
|
||||
func opMarshalable(op, key string, value interface{}) map[string]map[string]interface{} {
|
||||
if len(key) == 0 {
|
||||
func opMarshalable(op, key string, value interface{}) map[string]interface{} {
|
||||
if len(key) == 0 && value == nil {
|
||||
return nil
|
||||
}
|
||||
m := map[string]map[string]interface{}{
|
||||
m := map[string]interface{}{
|
||||
op: map[string]interface{}{
|
||||
key: value,
|
||||
},
|
||||
}
|
||||
if len(key) == 0 {
|
||||
m[op] = 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()
|
||||
switch m["$set"].(type) {
|
||||
case map[string]interface{}:
|
||||
m["$set"].(map[string]interface{})[entity.Modified] = time.Now().UnixNano()
|
||||
case bson.M:
|
||||
m["$set"].(bson.M)[entity.Modified] = time.Now().UnixNano()
|
||||
//case primitive.M:
|
||||
//m["$set"].(primitive.M)[entity.Modified] = time.Now().UnixNano()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user