New API tested
This commit is contained in:
@@ -316,7 +316,29 @@ func applySet(doc, operator bson.M) (bson.M, error) {
|
||||
if k == entity.Name {
|
||||
return nil, errModifiedReserved
|
||||
}
|
||||
doc[k] = v
|
||||
nesting := strings.Split(k, ".")
|
||||
if len(nesting) > 1 {
|
||||
mInterface, ok := doc[nesting[0]]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("path does not exist: %s (%s): %+v", k, nesting[0], doc)
|
||||
}
|
||||
m, ok := mInterface.(map[string]interface{})
|
||||
if !ok {
|
||||
pm, pmok := mInterface.(primitive.M)
|
||||
m = map[string]interface{}(pm)
|
||||
ok = pmok
|
||||
}
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("subpath cannot be followed for non object: %s (%s): %+v (%T)", k, nesting[0], mInterface, mInterface)
|
||||
}
|
||||
subdoc, err := applySet(bson.M(m), bson.M{strings.Join(nesting[1:], "."): v})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc[nesting[0]] = subdoc
|
||||
} else {
|
||||
doc[k] = v
|
||||
}
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user