-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'in' operator does not work for a JSON field #7952
Comments
Sorry I made a mistake in the issue labeling, it should be V3, not V2 |
In the interim you could try mapping the array to the below format, it's not ideal but it does work at least.
|
Yes good one, I made this workaround for now if someone else has this issue: Function that generates a list of queries const getContainsAdditionalDataTypeQueries = (
numbers: number[],
): { 'additional_data.type': { contains: number } }[] => {
return numbers.map((number) => ({
'additional_data.type': {
contains: number,
},
}))
} Just change: const additionalDataTypes = getContainsAdditionalDataTypeQueries(typeValues)
return combineQueries(baseWhere, {
and: [
{
'additional_data.type': {
exists: true,
},
},
{
or: [...additionalDataTypes],
},
],
}) |
…8148) Closes #7952 Adds support for `in` and `not_in` operator against JSON field filters. The following queries are now valid in postgres as well, previously it only worked in mongo ```ts await payload.find({ collection: 'posts', where: { 'data.value': { in: ['12', '13', '14'], }, }, context: { disable: true, }, }) await payload.find({ collection: 'posts', where: { 'data.value': { not_in: ['12', '13', '14'], }, }, context: { disable: true, }, }) ```
^ this PR Has been merged, this feature will be available in the next release. Let me know how it goes for you! |
🚀 This is included in version v3.0.0-beta.104 |
Works like a charm! Many thanks! ♥ |
This issue has been automatically locked. |
Link to reproduction
No response
Describe the Bug
I am using a JSON field in my collection to add any additional data as properties can differ per object in my collection.
So far it it works nice with querying, for example I use:
But now I need to do a check where a value exists within a provided array
And here is where I get an error:
node_modules\.pnpm\@[email protected][email protected][email protected][email protected]_w7w4zxyiztt4w5bs3ue2nosiyu\node_modules\@payloadcms\drizzle\dist\queries\parseParams.js (109:62) @ parseParams ⨯ TypeError: Cannot read properties of undefined (reading 'wildcard')
Looking at the code in the function parseParams I see that
in
is not supported:My question is this intended to not allow the
in
operator or is it a bug and it should be added?To Reproduce
Payload Version
3.0.0-beta.84
Adapters and Plugins
@payloadcms/db-postgres
The text was updated successfully, but these errors were encountered: