permit updat eto update
This commit is contained in:
@@ -16,10 +16,6 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var (
|
||||
errModifiedReserved = errors.New("cannot modify reserved field " + entity.Name)
|
||||
)
|
||||
|
||||
type BoltDB struct {
|
||||
db *bolt.DB
|
||||
}
|
||||
@@ -247,9 +243,6 @@ func apply(doc bson.M, operator interface{}) (bson.M, error) {
|
||||
if err := bson.Unmarshal(b, &op); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := op[entity.Name]; ok {
|
||||
return nil, errModifiedReserved
|
||||
}
|
||||
for k, v := range op {
|
||||
operateBM, ok := v.(bson.M)
|
||||
if !ok {
|
||||
@@ -282,7 +275,7 @@ func apply(doc bson.M, operator interface{}) (bson.M, error) {
|
||||
func applyUnset(doc, operator bson.M) (bson.M, error) {
|
||||
for k := range operator {
|
||||
if k == entity.Name {
|
||||
return nil, errModifiedReserved
|
||||
continue
|
||||
}
|
||||
nesting := strings.Split(k, ".")
|
||||
if len(nesting) > 1 {
|
||||
@@ -315,7 +308,7 @@ func applyUnset(doc, operator bson.M) (bson.M, error) {
|
||||
func applySet(doc, operator bson.M) (bson.M, error) {
|
||||
for k, v := range operator {
|
||||
if k == entity.Name {
|
||||
return nil, errModifiedReserved
|
||||
continue
|
||||
}
|
||||
nesting := strings.Split(k, ".")
|
||||
if len(nesting) > 1 {
|
||||
|
||||
@@ -188,10 +188,6 @@ func TestBoltDBUpdate(t *testing.T) {
|
||||
i++
|
||||
}
|
||||
|
||||
if err := bdb.Update(context.TODO(), testNS, ones[0].Query(), operator.Set{Key: entity.Name, Value: "NEWNAME"}); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := bdb.Update(context.TODO(), testNS, ones[0].Query(), operator.Set{Key: entity.Title, Value: "NEWTITLE"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user