If you have a schema property that is an array, and you run a query to search for a value $in the array, the querySyntax function does not allow for this. So, if I have a schema
and then I write the query to search for records who's owners are among some list of ids like so:
owners: { $in: [some, list, of, ownerIds] }
This code
$in: { type: 'array', items: definition },
from @feathersjs/schema/src/json-schema.js line 115 will throw an error if each item in my array is not an array - since the schema type of definition - being owners - is an array.
You can go around this by simply writing your query
owners: [some,list,of,ownerIds]
This works fine. It just departs from the allowed $in operations that mongo, for example, allows for. It creates some unnecessary complexity with programmatically writing queries using $in operator for different possible scenarios.
It's not an urgent bug, or necessarily even a bug, but I would think an anyOf allowing for the items of the $in querySchema validator to be either the definition or if the definition is an array, the type of the items from definition.
If not, it would help to have it be clearly documented. Where I discovered this was in a piece of code that has otherwise worked for a long time, and it was painful to find it because I didn't read it as an error even when I looked at my query language.
If you have a schema property that is an array, and you run a query to search for a value $in the array, the querySyntax function does not allow for this. So, if I have a schema
... owners: { type: 'array', items: ObjectIdSchema() } ...
and then I write the query to search for records who's
owners
are among some list of ids like so:owners: { $in: [some, list, of, ownerIds] }
This code
$in: { type: 'array', items: definition },
from @feathersjs/schema/src/json-schema.js line 115 will throw an error if each item in my array is not an array - since the schema type of
definition
- beingowners
- is an array.You can go around this by simply writing your query
owners: [some,list,of,ownerIds]
This works fine. It just departs from the allowed $in operations that mongo, for example, allows for. It creates some unnecessary complexity with programmatically writing queries using $in operator for different possible scenarios.
It's not an urgent bug, or necessarily even a bug, but I would think an
anyOf
allowing for theitems
of the $in querySchema validator to be either thedefinition
or if the definition is an array, the type of theitems
fromdefinition
.If not, it would help to have it be clearly documented. Where I discovered this was in a piece of code that has otherwise worked for a long time, and it was painful to find it because I didn't read it as an error even when I looked at my query language.