Skip to content

Commit

Permalink
Add $keyMapMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed Jul 16, 2024
1 parent e8fc259 commit d7db50a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions x/mango2/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 17 additions & 2 deletions x/mango2/ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit d7db50a

Please sign in to comment.