diff --git a/coperator.go b/coperator.go index f2136f7..ee037e0 100644 --- a/coperator.go +++ b/coperator.go @@ -97,7 +97,7 @@ func DocumentOperator(doc *Document, vfilter Filter, key string, value interface } continue } - if f, ok := v.(Filter); ok { + if f, ok := v.(map[string]interface{}); ok { ret, err = FieldOperator(doc, f, k, nil) if !ret { return ret, err @@ -133,7 +133,7 @@ func FieldOperator(doc *Document, vfilter Filter, key string, value interface{}) if !ok { return false, errors.New("unsupport operator") } - if fv, ok := v.(Filter); ok { + if fv, ok := v.(map[string]interface{}); ok { ret, err = opFn(doc, fv, key, nil) if !ret { return ret, err diff --git a/coperator_test.go b/coperator_test.go index 8c409aa..4c8ad7a 100644 --- a/coperator_test.go +++ b/coperator_test.go @@ -105,7 +105,7 @@ func TestValueOperator(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, _ := ValueOperator(&tt.doc, Filter{}, strings.Join(tt.path, "."), tt.value) + got, _ := ValueOperator(&tt.doc, map[string]interface{}{}, strings.Join(tt.path, "."), tt.value) if got != tt.want { t.Errorf("Document.GetPathArray() = %v, want %v", got, tt.want) } @@ -127,7 +127,7 @@ func TestDocumentOperator(t *testing.T) { "id": 1, }, }, - filter: Filter{ + filter: map[string]interface{}{ "user.id": 1, }, want: true, @@ -137,8 +137,8 @@ func TestDocumentOperator(t *testing.T) { doc: Document{ "age": 18, }, - filter: Filter{ - "age": Filter{ + filter: map[string]interface{}{ + "age": map[string]interface{}{ "$gt": 17, }, }, @@ -149,8 +149,8 @@ func TestDocumentOperator(t *testing.T) { doc: Document{ "age": 18, }, - filter: Filter{ - "age": Filter{ + filter: map[string]interface{}{ + "age": map[string]interface{}{ "$gt": 17, "$lt": 16, }, @@ -162,8 +162,8 @@ func TestDocumentOperator(t *testing.T) { doc: Document{ "age": 18, }, - filter: Filter{ - "age": Filter{ + filter: map[string]interface{}{ + "age": map[string]interface{}{ "$in": []interface{}{16, 17, 18}, }, }, @@ -174,8 +174,8 @@ func TestDocumentOperator(t *testing.T) { doc: Document{ "age": 22, }, - filter: Filter{ - "age": Filter{ + filter: map[string]interface{}{ + "age": map[string]interface{}{ "$nin": []interface{}{16, 17, 18}, }, },