You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch allows using `filter={field:{$elemMatch:{subfield:"foo"}}}` or
`filter={field:{$elemMatch:{subfield:{$regex:"^foo"}}}}` where `field` is an array
containing an object, and `subfield` is object field.
Also make `rest-layer-mem` match Mongo behaviour in this usecase.
Copy file name to clipboardExpand all lines: README.md
+38-12Lines changed: 38 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -919,20 +919,46 @@ The same example with flags:
919
919
However, keep in mind that Storers have to support regular expression and depending on the implementation of the storage handler the accepted syntax may vary.
920
920
An error of `ErrNotImplemented` will be returned for those storage backends which do not support the `$regex` operator.
921
921
922
+
The `$elemMatch` operator matches documents that contain an array field with at least one element that matches all the specified query criteria.
923
+
```go
924
+
"telephones":schema.Field{
925
+
Filterable:true,
926
+
Validator:&schema.Array{
927
+
Values:schema.Field{
928
+
Validator:&schema.Object{Schema:&Telephone},
929
+
},
930
+
},
931
+
},
932
+
```
933
+
934
+
Matching documents that contain specific values within array objects can be done with `$elemMatch`:
The snippet above will return all documents, which `telephones` array field contains objects that have `name` **_AND_** `active` fields matching queried values.
939
+
> Note that documents returned may contain other objects in `telephones` that don't match the query above, but at least one object will do. Further filtering could be needed on the API client side.
940
+
941
+
#### *$elemMatch* Limitation
942
+
`$elemMatch` will work only for arrays of objects for now. Later it could be extended to work on plain arrays e.g:
0 commit comments