diff --git a/coperator.go b/coperator.go index d37ea73..f2136f7 100644 --- a/coperator.go +++ b/coperator.go @@ -72,14 +72,17 @@ func (d *Document) GetPathArray(path []string) interface{} { } type Collection []Document -type Filter map[string]interface{} +type Filter interface{} type Operator func(doc *Document, filter Filter, key string, value interface{}) (bool, error) var operatorMap = map[string]Operator{} -func DocumentOperator(doc *Document, filter Filter, key string, value interface{}) (ret bool, err error) { - +func DocumentOperator(doc *Document, vfilter Filter, key string, value interface{}) (ret bool, err error) { + filter, ok := vfilter.(map[string]interface{}) + if !ok { + return false, errors.New("filter must be a map") + } for k, v := range filter { if strings.HasPrefix(k, "$") { @@ -117,7 +120,11 @@ func ValueOperator(doc *Document, filter Filter, key string, value interface{}) return true, nil } -func FieldOperator(doc *Document, filter Filter, key string, value interface{}) (ret bool, err error) { +func FieldOperator(doc *Document, vfilter Filter, key string, value interface{}) (ret bool, err error) { + filter, ok := vfilter.(map[string]interface{}) + if !ok { + return false, errors.New("filter must be a map") + } for k, v := range filter { if !strings.HasPrefix(k, "$") { return false, errors.New("uncorrect grammar")