Closed Stefan94V closed 2 months ago
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.
await payload.find({
collection: 'some-collection',
where: {
or: [
{
'additional_data.fieldX': {
contains: 1,
},
},
{
'additional_data.fieldX': {
contains: 2,
},
},
// Rest of the array...
],
},
})
In the interim you could try mapping the array to the below format, it's not ideal but it does work at least.
await payload.find({ collection: 'some-collection', where: { or: [ { 'additional_data.fieldX': { contains: 1, }, }, { 'additional_data.fieldX': { contains: 2, }, }, // Rest of the array... ], }, })
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: 'additional_data.type'
to the field you want and the input numbers
to the list you would like to query on
const additionalDataTypes = getContainsAdditionalDataTypeQueries(typeValues)
return combineQueries(baseWhere, {
and: [
{
'additional_data.type': {
exists: true,
},
},
{
or: [...additionalDataTypes],
},
],
})
^ 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
^ this PR Has been merged, this feature will be available in the next release. Let me know how it goes for you!
Works like a charm! Many thanks! ♥
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.
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\@payloadcms+drizzle@3.0.0-beta.84_payload@3.0.0-beta.84_pg@8.11.3_react@19.0.0-rc-fb9a90fa48-_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
Query the field
Error should throw
Payload Version
3.0.0-beta.84
Adapters and Plugins
@payloadcms/db-postgres