diff --git a/x/mango2/ast/ast.go b/x/mango2/ast/ast.go index 608fcb3ce..e2ae7f6fc 100644 --- a/x/mango2/ast/ast.go +++ b/x/mango2/ast/ast.go @@ -83,7 +83,7 @@ func Parse(input []byte) (Selector, error) { } switch op { - case OpElemMatch, OpAllMatch: + case OpElemMatch, OpAllMatch, OpKeyMapMatch: sels = append(sels, &fieldSelector{ field: k, cond: &elementSelector{ @@ -192,7 +192,7 @@ func opAndValue(input json.RawMessage) (Operator, interface{}, error) { return "", nil, fmt.Errorf("%s: %w", k, err) } return OpAll, value, nil - case OpElemMatch, OpAllMatch: + case OpElemMatch, OpAllMatch, OpKeyMapMatch: sel, err := Parse(v) if err != nil { return "", nil, fmt.Errorf("%s: %w", k, err) diff --git a/x/mango2/ast/ast_test.go b/x/mango2/ast/ast_test.go index 8f55b4620..112ffd4f8 100644 --- a/x/mango2/ast/ast_test.go +++ b/x/mango2/ast/ast_test.go @@ -441,11 +441,26 @@ func TestParse(t *testing.T) { }, }, }) + tests.Add("$keyMapMatch", test{ + input: `{"cameras": {"$keyMapMatch": {"$eq": "secondary"}}}`, + want: &fieldSelector{ + field: "cameras", + cond: &elementSelector{ + op: OpKeyMapMatch, + cond: &conditionSelector{ + op: OpEqual, + value: "secondary", + }, + }, + }, + }) + tests.Add("element selector with invalid selector", test{ + input: `{"cameras": {"$keyMapMatch": 42}}`, + wantErr: "$keyMapMatch: json: cannot unmarshal number into Go value of type map[string]json.RawMessage", + }) /* TODO: - - $keyMapMatch - - $mod with non-integer values returns 404 (WTF) https://docs.couchdb.org/en/stable/api/database/find.html#condition-operators */